Skip to content

Commit 31e192f

Browse files
committed
bitcoin#16710: Enable -Wsuggest-override if available
1 parent 2a26b11 commit 31e192f

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

configure.ac

+6
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=date-time],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=date-time"],,[[$CXXFLAG_WERROR]])
369369
AX_CHECK_COMPILE_FLAG([-Werror=return-type],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=return-type"],,[[$CXXFLAG_WERROR]])
370370
AX_CHECK_COMPILE_FLAG([-Werror=conditional-uninitialized],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=conditional-uninitialized"],,[[$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
@@ -383,6 +387,8 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
383387
AX_CHECK_COMPILE_FLAG([-Wunused-variable],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunused-variable"],,[[$CXXFLAG_WERROR]])
384388
AX_CHECK_COMPILE_FLAG([-Wdate-time],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdate-time"],,[[$CXXFLAG_WERROR]])
385389
AX_CHECK_COMPILE_FLAG([-Wconditional-uninitialized],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wconditional-uninitialized"],,[[$CXXFLAG_WERROR]])
390+
AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
391+
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
386392

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

src/Makefile.leveldb.include

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX
3030
endif
3131

3232
leveldb_libleveldb_a_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS)
33-
leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized, $(AM_CXXFLAGS)) $(PIE_FLAGS)
33+
leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override, $(AM_CXXFLAGS)) $(PIE_FLAGS)
3434

3535
leveldb_libleveldb_a_SOURCES=
3636
leveldb_libleveldb_a_SOURCES += leveldb/port/atomic_pointer.h

src/qt/rpcconsole.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <univalue.h>
2828

2929
#ifdef ENABLE_WALLET
30-
#include <db_cxx.h>
30+
#include <wallet/db.h>
3131
#endif
3232

3333
#include <QButtonGroup>
@@ -507,7 +507,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags
507507

508508
// set library version labels
509509
#ifdef ENABLE_WALLET
510-
ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0));
510+
ui->berkeleyDBVersion->setText(QString::fromStdString(BerkeleyDatabaseVersion()));
511511
std::string walletPath = GetDataDir().string();
512512
walletPath += QDir::separator().toLatin1() + gArgs.GetArg("-wallet", "wallet.dat");
513513
ui->wallet_path->setText(QString::fromStdString(walletPath));

src/wallet/db.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& er
338338
BerkeleyEnvironment* env = GetWalletEnv(file_path, walletFile);
339339
fs::path walletDir = env->Directory();
340340

341-
LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
341+
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
342342
LogPrintf("Using wallet %s\n", walletFile);
343343

344344
// Wallet file must be a plain filename without a directory
@@ -860,3 +860,8 @@ void BerkeleyDatabase::ReloadDbEnv()
860860
env->ReloadDbEnv();
861861
}
862862
}
863+
864+
std::string BerkeleyDatabaseVersion()
865+
{
866+
return DbEnv::version(nullptr, nullptr, nullptr);
867+
}

src/wallet/db.h

+9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@
2121
#include <unordered_map>
2222
#include <vector>
2323

24+
#if defined(__GNUC__) && !defined(__clang__)
25+
#pragma GCC diagnostic push
26+
#pragma GCC diagnostic ignored "-Wsuggest-override"
27+
#endif
2428
#include <db_cxx.h>
29+
#if defined(__GNUC__) && !defined(__clang__)
30+
#pragma GCC diagnostic pop
31+
#endif
2532

2633
static const unsigned int DEFAULT_WALLET_DBLOGSIZE = 100;
2734
static const bool DEFAULT_WALLET_PRIVDB = true;
@@ -419,4 +426,6 @@ class BerkeleyBatch
419426
bool static Rewrite(BerkeleyDatabase& database, const char* pszSkip = nullptr);
420427
};
421428

429+
std::string BerkeleyDatabaseVersion();
430+
422431
#endif // BITCOIN_WALLET_DB_H

0 commit comments

Comments
 (0)