Skip to content

Commit

Permalink
bitcoin#16710: Enable -Wsuggest-override if available
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Jun 17, 2021
1 parent 638fdf2 commit b07abef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions configure.ac
Expand Up @@ -368,6 +368,10 @@ if test "x$enable_werror" = "xyes"; then
AX_CHECK_COMPILE_FLAG([-Werror=date-time],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=date-time"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=return-type],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=return-type"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=conditional-uninitialized],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=conditional-uninitialized"],,[[$CXXFLAG_WERROR]])
dnl -Wsuggest-override is broken with GCC before 9.2
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78010
AX_CHECK_COMPILE_FLAG([-Werror=suggest-override],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=suggest-override"],,[[$CXXFLAG_WERROR]],
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
fi

if test "x$CXXFLAGS_overridden" = "xno"; then
Expand All @@ -383,6 +387,8 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
AX_CHECK_COMPILE_FLAG([-Wunused-variable],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunused-variable"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wdate-time],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdate-time"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wconditional-uninitialized],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wconditional-uninitialized"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])

## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
## unknown options if any other warning is produced. Test the -Wfoo case, and
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.leveldb.include
Expand Up @@ -30,7 +30,7 @@ LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX
endif

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

leveldb_libleveldb_a_SOURCES=
leveldb_libleveldb_a_SOURCES += leveldb/port/atomic_pointer.h
Expand Down
4 changes: 2 additions & 2 deletions src/qt/rpcconsole.cpp
Expand Up @@ -27,7 +27,7 @@
#include <univalue.h>

#ifdef ENABLE_WALLET
#include <db_cxx.h>
#include <wallet/db.h>
#endif

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

// set library version labels
#ifdef ENABLE_WALLET
ui->berkeleyDBVersion->setText(DbEnv::version(0, 0, 0));
ui->berkeleyDBVersion->setText(QString::fromStdString(BerkeleyDatabaseVersion()));
std::string walletPath = GetDataDir().string();
walletPath += QDir::separator().toLatin1() + gArgs.GetArg("-wallet", "wallet.dat");
ui->wallet_path->setText(QString::fromStdString(walletPath));
Expand Down
7 changes: 6 additions & 1 deletion src/wallet/db.cpp
Expand Up @@ -338,7 +338,7 @@ bool BerkeleyBatch::VerifyEnvironment(const fs::path& file_path, std::string& er
BerkeleyEnvironment* env = GetWalletEnv(file_path, walletFile);
fs::path walletDir = env->Directory();

LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
LogPrintf("Using wallet %s\n", walletFile);

// Wallet file must be a plain filename without a directory
Expand Down Expand Up @@ -860,3 +860,8 @@ void BerkeleyDatabase::ReloadDbEnv()
env->ReloadDbEnv();
}
}

std::string BerkeleyDatabaseVersion()
{
return DbEnv::version(nullptr, nullptr, nullptr);
}
9 changes: 9 additions & 0 deletions src/wallet/db.h
Expand Up @@ -21,7 +21,14 @@
#include <unordered_map>
#include <vector>

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsuggest-override"
#endif
#include <db_cxx.h>
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

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

std::string BerkeleyDatabaseVersion();

#endif // BITCOIN_WALLET_DB_H

0 comments on commit b07abef

Please sign in to comment.