Skip to content

Commit

Permalink
Merge #99: cmake: Silent leveldb-specific warnings
Browse files Browse the repository at this point in the history
33dee19 fixup! cmake: Build `leveldb` static library (Hennadii Stepanov)

Pull request description:

  This PR split from #84

  It introduces a new `warn_leveldb_interface`, which overrides `-Wconditional-uninitialized` and `-Wsuggest-override` if any.

  For MSVC builds, dropped warning suppressions that are provided at the global level.

  For example, on the staging branch:
  ```
  $ env CC=clang CXX=clang++ CXXFLAGS="-Wconditional-uninitialized -Wsuggest-override" cmake -B build
  $ cmake --build build --target leveldb > /dev/null
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:474:17: warning: 'Name' overrides a member function but is not marked 'override' [-Wsuggest-override]
      const char* Name() const { return rep_->Name(); }
                  ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:110:15: note: overridden virtual function is here
    const char* Name() const override { return (*name_)(state_); }
                ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:475:10: warning: 'CreateFilter' overrides a member function but is not marked 'override' [-Wsuggest-override]
      void CreateFilter(const Slice* keys, int n, std::string* dst) const {
           ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:112:8: note: overridden virtual function is here
    void CreateFilter(const Slice* keys, int n, std::string* dst) const override {
         ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:478:10: warning: 'KeyMayMatch' overrides a member function but is not marked 'override' [-Wsuggest-override]
      bool KeyMayMatch(const Slice& key, const Slice& filter) const {
           ^
  /home/hebasto/git/bitcoin/src/leveldb/db/c.cc:125:8: note: overridden virtual function is here
    bool KeyMayMatch(const Slice& key, const Slice& filter) const override {
         ^
  3 warnings generated.
  /home/hebasto/git/bitcoin/src/leveldb/db/version_set.cc:1016:55: warning: variable 'manifest_size' may be uninitialized when used here [-Wconditional-uninitialized]
    descriptor_log_ = new log::Writer(descriptor_file_, manifest_size);
                                                        ^~~~~~~~~~~~~
  /home/hebasto/git/bitcoin/src/leveldb/db/version_set.cc:997:25: note: initialize the variable 'manifest_size' to silence this warning
    uint64_t manifest_size;
                          ^
                           = 0
  1 warning generated.
  ```

ACKs for top commit:
  vasild:
    ACK 33dee19
  theuni:
    ACK 33dee19

Tree-SHA512: ffe9efc438bc808a42abaa42a45f7073c1e3cdd6404e9b8b811e94b304c2464f3df26c276d363c97a3941d50f0e6bcb3788f1d870dd23df86b0d9a33363b7e77
  • Loading branch information
hebasto committed Feb 15, 2024
2 parents 9b72eb1 + 33dee19 commit 2082e3d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions cmake/leveldb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,23 @@ target_include_directories(leveldb
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/leveldb/include>
)

add_library(nowarn_leveldb_interface INTERFACE)
if(MSVC)
target_compile_options(leveldb
PRIVATE
/wd4244
/wd4267
$<$<CONFIG:Release>:/wd4722>
target_compile_options(nowarn_leveldb_interface INTERFACE
/wd4722
)
target_compile_definitions(leveldb
PRIVATE
_CRT_NONSTDC_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS
target_compile_definitions(nowarn_leveldb_interface INTERFACE
_CRT_NONSTDC_NO_WARNINGS
)
else()
target_compile_options(nowarn_leveldb_interface INTERFACE
-Wno-conditional-uninitialized
-Wno-suggest-override
)
endif()

#TODO: figure out how to filter out:
# -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override

target_link_libraries(leveldb PRIVATE core_interface crc32c)
target_link_libraries(leveldb PRIVATE
core_interface
nowarn_leveldb_interface
crc32c
)

0 comments on commit 2082e3d

Please sign in to comment.