Skip to content

Commit 219c55d

Browse files
committed
Merge #16710: build: Enable -Wsuggest-override if available
839add1 build: Enable -Wsuggest-override (Hennadii Stepanov) de5e91c refactor: Add BerkeleyDatabaseVersion() function (Hennadii Stepanov) Pull request description: From GCC [docs](https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html): > `-Wsuggest-override` > Warn about overriding virtual functions that are not marked with the override keyword. ~This PR is based on #16722 (the first commit).~ See: bitcoin/bitcoin#16722 (comment) ACKs for top commit: fanquake: ACK 839add1 vasild: ACK 839add1 practicalswift: ACK 839add1 assuming Travis is happy: patch looks correct Tree-SHA512: 1e8cc085da30d41536deff9b181962c1882314ab252c2ad958294087ae1e5a0dfa4886bdbe36f21cf6ae71df776a8420f349f007d4b5b49fd79ba98ce308965a
2 parents 8da1e43 + 839add1 commit 219c55d

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ if test "x$enable_werror" = "xyes"; then
368368
AX_CHECK_COMPILE_FLAG([-Werror=return-type],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=return-type"],,[[$CXXFLAG_WERROR]])
369369
AX_CHECK_COMPILE_FLAG([-Werror=conditional-uninitialized],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=conditional-uninitialized"],,[[$CXXFLAG_WERROR]])
370370
AX_CHECK_COMPILE_FLAG([-Werror=sign-compare],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=sign-compare"],,[[$CXXFLAG_WERROR]])
371+
dnl -Wsuggest-override is broken with GCC before 9.2
372+
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78010
373+
AX_CHECK_COMPILE_FLAG([-Werror=suggest-override],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=suggest-override"],,[[$CXXFLAG_WERROR]],
374+
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
371375
fi
372376

373377
if test "x$CXXFLAGS_overridden" = "xno"; then
@@ -385,6 +389,8 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
385389
AX_CHECK_COMPILE_FLAG([-Wdate-time],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdate-time"],,[[$CXXFLAG_WERROR]])
386390
AX_CHECK_COMPILE_FLAG([-Wconditional-uninitialized],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wconditional-uninitialized"],,[[$CXXFLAG_WERROR]])
387391
AX_CHECK_COMPILE_FLAG([-Wsign-compare],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsign-compare"],,[[$CXXFLAG_WERROR]])
392+
AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
393+
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
388394

389395
dnl Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
390396
dnl unknown options if any other warning is produced. Test the -Wfoo case, and

src/Makefile.leveldb.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX
3636
endif
3737

3838
leveldb_libleveldb_a_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS)
39-
leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized, $(AM_CXXFLAGS)) $(PIE_FLAGS)
39+
leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override, $(AM_CXXFLAGS)) $(PIE_FLAGS)
4040

4141
leveldb_libleveldb_a_SOURCES=
4242
leveldb_libleveldb_a_SOURCES += leveldb/port/port_stdcxx.h

src/qt/rpcconsole.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <univalue.h>
2525

2626
#ifdef ENABLE_WALLET
27-
#include <db_cxx.h>
27+
#include <wallet/db.h>
2828
#include <wallet/wallet.h>
2929
#endif
3030

@@ -34,9 +34,10 @@
3434
#include <QScrollBar>
3535
#include <QScreen>
3636
#include <QSettings>
37+
#include <QString>
38+
#include <QStringList>
3739
#include <QTime>
3840
#include <QTimer>
39-
#include <QStringList>
4041

4142
// TODO: add a scrollback limit, as there is currently none
4243
// TODO: make it possible to filter out categories (esp debug messages when implemented)
@@ -480,7 +481,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
480481

481482
// set library version labels
482483
#ifdef ENABLE_WALLET
483-
ui->berkeleyDBVersion->setText(DbEnv::version(nullptr, nullptr, nullptr));
484+
ui->berkeleyDBVersion->setText(QString::fromStdString(BerkeleyDatabaseVersion()));
484485
#else
485486
ui->label_berkeleyDBVersion->hide();
486487
ui->berkeleyDBVersion->hide();

src/wallet/db.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, bilingual_str&
399399
std::shared_ptr<BerkeleyEnvironment> env = GetWalletEnv(file_path, walletFile);
400400
fs::path walletDir = env->Directory();
401401

402-
LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(nullptr, nullptr, nullptr));
402+
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
403403
LogPrintf("Using wallet %s\n", file_path.string());
404404

405405
if (!env->Open(true /* retry */)) {
@@ -916,3 +916,8 @@ void BerkeleyDatabase::ReloadDbEnv()
916916
env->ReloadDbEnv();
917917
}
918918
}
919+
920+
std::string BerkeleyDatabaseVersion()
921+
{
922+
return DbEnv::version(nullptr, nullptr, nullptr);
923+
}

src/wallet/db.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
#include <unordered_map>
2020
#include <vector>
2121

22+
#if defined(__GNUC__) && !defined(__clang__)
23+
#pragma GCC diagnostic push
24+
#pragma GCC diagnostic ignored "-Wsuggest-override"
25+
#endif
2226
#include <db_cxx.h>
27+
#if defined(__GNUC__) && !defined(__clang__)
28+
#pragma GCC diagnostic pop
29+
#endif
2330

2431
struct bilingual_str;
2532

@@ -402,4 +409,6 @@ class BerkeleyBatch
402409
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
403410
};
404411

412+
std::string BerkeleyDatabaseVersion();
413+
405414
#endif // BITCOIN_WALLET_DB_H

0 commit comments

Comments
 (0)