Skip to content

Commit

Permalink
GCC builds w/o warnings now
Browse files Browse the repository at this point in the history
- Turned off -Wformat in Linux builds since it causes warnings
  everywhere we pass int64_t through a printf-type function, which
  is not actually a problem.
- Removed CBL_CORE_API and FLEECE_PUBLIC in .cc files; GCC warned
  the 'visibility' attribute is ignored in that context.
- Suppressed a false "control reaches end of non-void function" in
  ExprNodes.cc.
- Fixed a few places in BLIP where values of different enum types are
  or-ed together.
  • Loading branch information
snej committed Sep 17, 2024
1 parent c6c1cdd commit 66ad5fc
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 31 deletions.
12 changes: 6 additions & 6 deletions C/c4Base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace litecore;


extern "C" {
CBL_CORE_API std::atomic_int gC4ExpectExceptions;
std::atomic_int gC4ExpectExceptions;
bool C4ExpectingExceptions();

bool C4ExpectingExceptions() { return gC4ExpectExceptions > 0; } // LCOV_EXCL_LINE
Expand Down Expand Up @@ -174,11 +174,11 @@ C4StringResult c4log_binaryFilePath(void) C4API {
}

// NOLINTBEGIN(misc-misplaced-const,cppcoreguidelines-interfaces-global-init)
CBL_CORE_API C4LogDomain const kC4DefaultLog = (C4LogDomain)&kC4Cpp_DefaultLog;
CBL_CORE_API C4LogDomain const kC4DatabaseLog = (C4LogDomain)&DBLog;
CBL_CORE_API C4LogDomain const kC4QueryLog = (C4LogDomain)&QueryLog;
CBL_CORE_API C4LogDomain const kC4SyncLog = (C4LogDomain)&SyncLog;
CBL_CORE_API C4LogDomain const kC4WebSocketLog = (C4LogDomain)&websocket::WSLogDomain;
C4LogDomain const kC4DefaultLog = (C4LogDomain)&kC4Cpp_DefaultLog;
C4LogDomain const kC4DatabaseLog = (C4LogDomain)&DBLog;
C4LogDomain const kC4QueryLog = (C4LogDomain)&QueryLog;
C4LogDomain const kC4SyncLog = (C4LogDomain)&SyncLog;
C4LogDomain const kC4WebSocketLog = (C4LogDomain)&websocket::WSLogDomain;

// NOLINTEND(misc-misplaced-const,cppcoreguidelines-interfaces-global-init)

Expand Down
2 changes: 1 addition & 1 deletion C/c4Certificate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace litecore::crypto;

#ifdef COUCHBASE_ENTERPRISE

CBL_CORE_API const C4CertIssuerParameters kDefaultCertIssuerParameters = {
const C4CertIssuerParameters kDefaultCertIssuerParameters = {
CertSigningRequest::kOneYear, C4STR("1"), -1, false, true, true, true};


Expand Down
4 changes: 2 additions & 2 deletions C/c4Database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ using namespace fleece;
using namespace litecore;


CBL_CORE_API const char* const kC4DatabaseFilenameExtension = ".cblite2";
const char* const kC4DatabaseFilenameExtension = ".cblite2";

CBL_CORE_API C4StorageEngine const kC4SQLiteStorageEngine = "SQLite";
C4StorageEngine const kC4SQLiteStorageEngine = "SQLite";

C4EncryptionKey C4EncryptionKeyFromPassword(slice password, C4EncryptionAlgorithm alg) {
C4EncryptionKey key;
Expand Down
2 changes: 1 addition & 1 deletion C/c4DocEnumerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace litecore;

#pragma mark - DOC ENUMERATION:

CBL_CORE_API const C4EnumeratorOptions kC4DefaultEnumeratorOptions = {kC4IncludeNonConflicted | kC4IncludeBodies};
const C4EnumeratorOptions kC4DefaultEnumeratorOptions = {kC4IncludeNonConflicted | kC4IncludeBodies};

class C4DocEnumerator::Impl
: public RecordEnumerator
Expand Down
2 changes: 1 addition & 1 deletion C/c4Query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace fleece::impl;
using namespace litecore;


CBL_CORE_API const C4QueryOptions kC4DefaultQueryOptions = {};
const C4QueryOptions kC4DefaultQueryOptions = {};

C4Query::C4Query(C4Collection* coll, C4QueryLanguage language, slice queryExpression)
: _database(asInternal(coll)->dbImpl())
Expand Down
3 changes: 3 additions & 0 deletions LiteCore/Query/Translator/ExprNodes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ namespace litecore::qt {
return result;
}
}
#ifdef __GNUC__
__builtin_unreachable(); // suppress GCC warning "control reaches end of non-void function"
#endif
}

ExprNode* ExprNode::parseArray(Array array, ParseContext& ctx) {
Expand Down
2 changes: 1 addition & 1 deletion LiteCore/Support/TestsCommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fleece::alloc_slice json5slice(string_view str) {

string json5(string_view str) { return string(json5slice(str)); }

extern "C" CBL_CORE_API std::atomic_int gC4ExpectExceptions;
extern "C" std::atomic_int gC4ExpectExceptions;

// While in scope, suppresses warnings about errors, and debugger exception breakpoints (in Xcode)
ExpectingExceptions::ExpectingExceptions() {
Expand Down
2 changes: 1 addition & 1 deletion Networking/BLIP/Message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ namespace litecore::blip {
uint8_t buf[kMaxVarintLen64];
alloc_slice payload(buf, PutUVarInt(buf, _rawBytesReceived));
Retained<MessageOut> ack =
new MessageOut(_connection, (FrameFlags)(msgType | kUrgent | kNoReply), payload, nullptr, _number);
new MessageOut(_connection, (FrameFlags)(FrameFlags(msgType) | kUrgent | kNoReply), payload, nullptr, _number);
_connection->send(ack);
_unackedBytes = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Networking/BLIP/MessageBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace litecore::blip {
}

FrameFlags MessageBuilder::flags() const {
int flags = type & kTypeMask;
int flags = type & int(kTypeMask);
if ( urgent ) flags |= kUrgent;
if ( compressed ) flags |= kCompressed;
if ( noreply ) flags |= kNoReply;
Expand Down
22 changes: 11 additions & 11 deletions REST/REST_CAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ using namespace std;
using namespace fleece;
using namespace litecore;

CBL_CORE_API C4ListenerAPIs c4listener_availableAPIs(void) noexcept { return C4Listener::availableAPIs(); }
C4ListenerAPIs c4listener_availableAPIs(void) noexcept { return C4Listener::availableAPIs(); }

CBL_CORE_API C4Listener* c4listener_start(const C4ListenerConfig* config, C4Error* outError) noexcept {
C4Listener* c4listener_start(const C4ListenerConfig* config, C4Error* outError) noexcept {
try {
return new C4Listener(*config);
}
catchError(outError) return nullptr;
}

CBL_CORE_API void c4listener_free(C4Listener* listener) noexcept { delete listener; }
void c4listener_free(C4Listener* listener) noexcept { delete listener; }

CBL_CORE_API C4StringResult c4db_URINameFromPath(C4String pathSlice) noexcept {
C4StringResult c4db_URINameFromPath(C4String pathSlice) noexcept {
try {
if ( string name = C4Listener::URLNameFromPath(pathSlice); name.empty() ) return {};
else
Expand All @@ -39,15 +39,15 @@ CBL_CORE_API C4StringResult c4db_URINameFromPath(C4String pathSlice) noexcept {
catchAndWarn() return {};
}

CBL_CORE_API bool c4listener_shareDB(C4Listener* listener, C4String name, C4Database* db, C4Error* outError) noexcept {
bool c4listener_shareDB(C4Listener* listener, C4String name, C4Database* db, C4Error* outError) noexcept {
try {
return listener->shareDB(name, db);
}
catchError(outError);
return false;
}

CBL_CORE_API bool c4listener_unshareDB(C4Listener* listener, C4Database* db, C4Error* outError) noexcept {
bool c4listener_unshareDB(C4Listener* listener, C4Database* db, C4Error* outError) noexcept {
try {
if ( listener->unshareDB(db) ) return true;
c4error_return(LiteCoreDomain, kC4ErrorNotOpen, "Database not shared"_sl, outError);
Expand All @@ -56,7 +56,7 @@ CBL_CORE_API bool c4listener_unshareDB(C4Listener* listener, C4Database* db, C4E
return false;
}

CBL_CORE_API bool c4listener_shareCollection(C4Listener* listener, C4String name, C4Collection* collection,
bool c4listener_shareCollection(C4Listener* listener, C4String name, C4Collection* collection,
C4Error* outError) noexcept {
try {
return listener->shareCollection(name, collection);
Expand All @@ -65,7 +65,7 @@ CBL_CORE_API bool c4listener_shareCollection(C4Listener* listener, C4String name
return false;
}

CBL_CORE_API bool c4listener_unshareCollection(C4Listener* listener, C4String name, C4Collection* collection,
bool c4listener_unshareCollection(C4Listener* listener, C4String name, C4Collection* collection,
C4Error* outError) noexcept {
try {
if ( listener->unshareCollection(name, collection) ) return true;
Expand All @@ -75,14 +75,14 @@ CBL_CORE_API bool c4listener_unshareCollection(C4Listener* listener, C4String na
return false;
}

CBL_CORE_API uint16_t c4listener_getPort(const C4Listener* listener) noexcept {
uint16_t c4listener_getPort(const C4Listener* listener) noexcept {
try {
return listener->port();
}
catchAndWarn() return 0;
}

CBL_CORE_API FLMutableArray c4listener_getURLs(const C4Listener* listener, C4Database* db, C4ListenerAPIs api,
FLMutableArray c4listener_getURLs(const C4Listener* listener, C4Database* db, C4ListenerAPIs api,
C4Error* err) noexcept {
try {
auto urls = fleece::MutableArray::newArray();
Expand All @@ -93,7 +93,7 @@ CBL_CORE_API FLMutableArray c4listener_getURLs(const C4Listener* listener, C4Dat
return nullptr;
}

CBL_CORE_API void c4listener_getConnectionStatus(const C4Listener* listener, unsigned* connectionCount,
void c4listener_getConnectionStatus(const C4Listener* listener, unsigned* connectionCount,
unsigned* activeConnectionCount) noexcept {
auto [conns, active] = listener->connectionStatus();
if ( connectionCount ) *connectionCount = conns;
Expand Down
2 changes: 1 addition & 1 deletion Replicator/c4Replicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ C4Cert* C4Replicator::getPeerTLSCertificate() const { return asInternal(this)->g
#endif


CBL_CORE_API const char* const kC4ReplicatorActivityLevelNames[6] = {"stopped", "offline", "connecting",
const char* const kC4ReplicatorActivityLevelNames[6] = {"stopped", "offline", "connecting",
"idle", "busy", "stopping"};

static bool isValidScheme(slice scheme) { return scheme.size > 0 && isalpha(scheme[0]); }
Expand Down
6 changes: 3 additions & 3 deletions cmake/platform_linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ function(setup_litecore_build_linux)
)
endforeach()

foreach(platform LiteCoreObjects LiteCoreUnitTesting BLIPObjects)
foreach(platform LiteCoreObjects LiteCoreUnitTesting BLIPObjects CppTests C4Tests)
target_compile_options(
${platform} PRIVATE
"-Wformat=2"
#"-Wformat=2"
"-Wno-format"
)
endforeach()
endfunction()

2 changes: 1 addition & 1 deletion cmake/platform_unix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function(setup_litecore_build_unix)
-Werror=unused-value
-Werror=uninitialized
-Werror=float-conversion
-Wformat=2
#-Wformat=2
#-Wshadow
#-Weffc++
)
Expand Down
2 changes: 1 addition & 1 deletion vendor/fleece

0 comments on commit 66ad5fc

Please sign in to comment.