merge bitcoin#21430: Add -Werror=implicit-fallthrough compile flag

This commit is contained in:
Kittywhiskers Van Gogh 2021-03-13 21:23:17 +02:00
parent cae5496d0b
commit 1fbdd009cd
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
7 changed files with 14 additions and 7 deletions

View File

@ -468,6 +468,7 @@ if test "x$enable_werror" = "xyes"; then
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])]) [AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
AX_CHECK_COMPILE_FLAG([-Werror=unreachable-code-loop-increment],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Werror=unreachable-code-loop-increment],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=mismatched-tags], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=mismatched-tags"], [], [$CXXFLAG_WERROR]) AX_CHECK_COMPILE_FLAG([-Werror=mismatched-tags], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=mismatched-tags"], [], [$CXXFLAG_WERROR])
AX_CHECK_COMPILE_FLAG([-Werror=implicit-fallthrough], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=implicit-fallthrough"], [], [$CXXFLAG_WERROR])
fi fi
if test "x$CXXFLAGS_overridden" = "xno"; then if test "x$CXXFLAGS_overridden" = "xno"; then
@ -494,6 +495,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$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; };]])]) [AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
AX_CHECK_COMPILE_FLAG([-Wunreachable-code-loop-increment],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wunreachable-code-loop-increment],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wimplicit-fallthrough"], [], [$CXXFLAG_WERROR])
dnl Some compilers (gcc) ignore unknown -Wno-* options, but warn about all dnl Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
dnl unknown options if any other warning is produced. Test the -Wfoo case, and dnl unknown options if any other warning is produced. Test the -Wfoo case, and
@ -501,7 +503,6 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wself-assign],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wself-assign],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-implicit-fallthrough"],,[[$CXXFLAG_WERROR]])
if test x$suppress_external_warnings != xyes ; then if test x$suppress_external_warnings != xyes ; then
AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"],,[[$CXXFLAG_WERROR]]) AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"],,[[$CXXFLAG_WERROR]])
fi fi

View File

@ -22,6 +22,7 @@ LEVELDB_CPPFLAGS_INT += -DHAVE_SNAPPY=0 -DHAVE_CRC32C=1
LEVELDB_CPPFLAGS_INT += -DHAVE_FDATASYNC=@HAVE_FDATASYNC@ LEVELDB_CPPFLAGS_INT += -DHAVE_FDATASYNC=@HAVE_FDATASYNC@
LEVELDB_CPPFLAGS_INT += -DHAVE_FULLFSYNC=@HAVE_FULLFSYNC@ LEVELDB_CPPFLAGS_INT += -DHAVE_FULLFSYNC=@HAVE_FULLFSYNC@
LEVELDB_CPPFLAGS_INT += -DHAVE_O_CLOEXEC=@HAVE_O_CLOEXEC@ LEVELDB_CPPFLAGS_INT += -DHAVE_O_CLOEXEC=@HAVE_O_CLOEXEC@
LEVELDB_CPPFLAGS_INT += -DFALLTHROUGH_INTENDED=[[fallthrough]]
if WORDS_BIGENDIAN if WORDS_BIGENDIAN
LEVELDB_CPPFLAGS_INT += -DLEVELDB_IS_BIG_ENDIAN=1 LEVELDB_CPPFLAGS_INT += -DLEVELDB_IS_BIG_ENDIAN=1

View File

@ -47,8 +47,10 @@ unsigned int MurmurHash3(unsigned int nHashSeed, Span<const unsigned char> vData
switch (vDataToHash.size() & 3) { switch (vDataToHash.size() & 3) {
case 3: case 3:
k1 ^= tail[2] << 16; k1 ^= tail[2] << 16;
[[fallthrough]];
case 2: case 2:
k1 ^= tail[1] << 8; k1 ^= tail[1] << 8;
[[fallthrough]];
case 1: case 1:
k1 ^= tail[0]; k1 ^= tail[0];
k1 *= c1; k1 *= c1;

View File

@ -288,6 +288,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
} }
if (breakParsing) if (breakParsing)
break; break;
[[fallthrough]];
} }
case STATE_ARGUMENT: // In or after argument case STATE_ARGUMENT: // In or after argument
case STATE_EATING_SPACES_IN_ARG: case STATE_EATING_SPACES_IN_ARG:
@ -401,6 +402,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
strResult = lastResult.get_str(); strResult = lastResult.get_str();
else else
strResult = lastResult.write(2); strResult = lastResult.write(2);
[[fallthrough]];
case STATE_ARGUMENT: case STATE_ARGUMENT:
case STATE_EATING_SPACES: case STATE_EATING_SPACES:
return true; return true;

View File

@ -521,6 +521,7 @@ static bool rest_getutxos(const CoreContext& context, HTTPRequest* req, const st
// convert hex to bin, continue then with bin part // convert hex to bin, continue then with bin part
std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable); std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
strRequestMutable.assign(strRequestV.begin(), strRequestV.end()); strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
[[fallthrough]];
} }
case RetFormat::BINARY: { case RetFormat::BINARY: {

View File

@ -888,7 +888,7 @@ static RPCHelpMan getblocktemplate()
case ThresholdState::LOCKED_IN: case ThresholdState::LOCKED_IN:
// Ensure bit is set in block version // Ensure bit is set in block version
pblock->nVersion |= g_versionbitscache.Mask(consensusParams, pos); pblock->nVersion |= g_versionbitscache.Mask(consensusParams, pos);
// FALL THROUGH to get vbavailable set... [[fallthrough]];
case ThresholdState::STARTED: case ThresholdState::STARTED:
{ {
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos]; const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];

View File

@ -797,27 +797,27 @@ inline const char* streamStateFromFormat(std::ostream& out, bool& positionalMode
break; break;
case 'X': case 'X':
out.setf(std::ios::uppercase); out.setf(std::ios::uppercase);
// Falls through [[fallthrough]];
case 'x': case 'p': case 'x': case 'p':
out.setf(std::ios::hex, std::ios::basefield); out.setf(std::ios::hex, std::ios::basefield);
intConversion = true; intConversion = true;
break; break;
case 'E': case 'E':
out.setf(std::ios::uppercase); out.setf(std::ios::uppercase);
// Falls through [[fallthrough]];
case 'e': case 'e':
out.setf(std::ios::scientific, std::ios::floatfield); out.setf(std::ios::scientific, std::ios::floatfield);
out.setf(std::ios::dec, std::ios::basefield); out.setf(std::ios::dec, std::ios::basefield);
break; break;
case 'F': case 'F':
out.setf(std::ios::uppercase); out.setf(std::ios::uppercase);
// Falls through [[fallthrough]];
case 'f': case 'f':
out.setf(std::ios::fixed, std::ios::floatfield); out.setf(std::ios::fixed, std::ios::floatfield);
break; break;
case 'A': case 'A':
out.setf(std::ios::uppercase); out.setf(std::ios::uppercase);
// Falls through [[fallthrough]];
case 'a': case 'a':
# ifdef _MSC_VER # ifdef _MSC_VER
// Workaround https://developercommunity.visualstudio.com/content/problem/520472/hexfloat-stream-output-does-not-ignore-precision-a.html // Workaround https://developercommunity.visualstudio.com/content/problem/520472/hexfloat-stream-output-does-not-ignore-precision-a.html
@ -829,7 +829,7 @@ inline const char* streamStateFromFormat(std::ostream& out, bool& positionalMode
break; break;
case 'G': case 'G':
out.setf(std::ios::uppercase); out.setf(std::ios::uppercase);
// Falls through [[fallthrough]];
case 'g': case 'g':
out.setf(std::ios::dec, std::ios::basefield); out.setf(std::ios::dec, std::ios::basefield);
// As in boost::format, let stream decide float format. // As in boost::format, let stream decide float format.