Skip to content

Commit 6baabc4

Browse files
committed
Merge bitcoin#21430: build: Add -Werror=implicit-fallthrough compile flag
3c4c8e7 build: Add -Werror=implicit-fallthrough compile flag (Hennadii Stepanov) 014110c Use C++17 [[fallthrough]] attribute, and drop -Wno-implicit-fallthrough (Hennadii Stepanov) Pull request description: ACKs for top commit: fanquake: ACK 3c4c8e7 - looks ok to me now. Checked that warnings occur in our code & leveldb by removing a `[[fallthrough]]` or `FALLTHROUGH_INTENDED`. jarolrod: ACK 3c4c8e7 theStack: ACK 3c4c8e7 Tree-SHA512: 4dce91f0f26b8a3de09bd92bb3d7e1995e078e3a8b3ff861c4fbf6c0b32b2327d063633b07b89c4aa94a1141d7f78d46d9d43ab8df865273e342693ad30645b6
2 parents f8b20fd + 3c4c8e7 commit 6baabc4

7 files changed

+14
-7
lines changed

configure.ac

+2-1
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ if test "x$enable_werror" = "xyes"; then
426426
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
427427
AX_CHECK_COMPILE_FLAG([-Werror=unreachable-code-loop-increment],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
428428
AX_CHECK_COMPILE_FLAG([-Werror=mismatched-tags], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=mismatched-tags"], [], [$CXXFLAG_WERROR])
429+
AX_CHECK_COMPILE_FLAG([-Werror=implicit-fallthrough], [ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=implicit-fallthrough"], [], [$CXXFLAG_WERROR])
429430

430431
if test x$suppress_external_warnings != xno ; then
431432
AX_CHECK_COMPILE_FLAG([-Werror=documentation],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=documentation"],,[[$CXXFLAG_WERROR]])
@@ -456,6 +457,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
456457
AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
457458
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
458459
AX_CHECK_COMPILE_FLAG([-Wunreachable-code-loop-increment],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
460+
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough], [WARN_CXXFLAGS="$WARN_CXXFLAGS -Wimplicit-fallthrough"], [], [$CXXFLAG_WERROR])
459461

460462
if test x$suppress_external_warnings != xno ; then
461463
AX_CHECK_COMPILE_FLAG([-Wdocumentation],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdocumentation"],,[[$CXXFLAG_WERROR]])
@@ -467,7 +469,6 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
467469
AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-parameter"],,[[$CXXFLAG_WERROR]])
468470
AX_CHECK_COMPILE_FLAG([-Wself-assign],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-self-assign"],,[[$CXXFLAG_WERROR]])
469471
AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
470-
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-implicit-fallthrough"],,[[$CXXFLAG_WERROR]])
471472
if test x$suppress_external_warnings != xyes ; then
472473
AX_CHECK_COMPILE_FLAG([-Wdeprecated-copy],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-deprecated-copy"],,[[$CXXFLAG_WERROR]])
473474
fi

src/Makefile.leveldb.include

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LEVELDB_CPPFLAGS_INT += -DHAVE_SNAPPY=0 -DHAVE_CRC32C=1
2222
LEVELDB_CPPFLAGS_INT += -DHAVE_FDATASYNC=@HAVE_FDATASYNC@
2323
LEVELDB_CPPFLAGS_INT += -DHAVE_FULLFSYNC=@HAVE_FULLFSYNC@
2424
LEVELDB_CPPFLAGS_INT += -DHAVE_O_CLOEXEC=@HAVE_O_CLOEXEC@
25+
LEVELDB_CPPFLAGS_INT += -DFALLTHROUGH_INTENDED=[[fallthrough]]
2526

2627
if WORDS_BIGENDIAN
2728
LEVELDB_CPPFLAGS_INT += -DLEVELDB_IS_BIG_ENDIAN=1

src/hash.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ unsigned int MurmurHash3(unsigned int nHashSeed, Span<const unsigned char> vData
4747
switch (vDataToHash.size() & 3) {
4848
case 3:
4949
k1 ^= tail[2] << 16;
50+
[[fallthrough]];
5051
case 2:
5152
k1 ^= tail[1] << 8;
53+
[[fallthrough]];
5254
case 1:
5355
k1 ^= tail[0];
5456
k1 *= c1;

src/qt/rpcconsole.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
288288
}
289289
if (breakParsing)
290290
break;
291+
[[fallthrough]];
291292
}
292293
case STATE_ARGUMENT: // In or after argument
293294
case STATE_EATING_SPACES_IN_ARG:
@@ -401,6 +402,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
401402
strResult = lastResult.get_str();
402403
else
403404
strResult = lastResult.write(2);
405+
[[fallthrough]];
404406
case STATE_ARGUMENT:
405407
case STATE_EATING_SPACES:
406408
return true;

src/rest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::
524524
// convert hex to bin, continue then with bin part
525525
std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
526526
strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
527+
[[fallthrough]];
527528
}
528529

529530
case RetFormat::BINARY: {

src/rpc/mining.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ static RPCHelpMan getblocktemplate()
850850
case ThresholdState::LOCKED_IN:
851851
// Ensure bit is set in block version
852852
pblock->nVersion |= g_versionbitscache.Mask(consensusParams, pos);
853-
// FALL THROUGH to get vbavailable set...
853+
[[fallthrough]];
854854
case ThresholdState::STARTED:
855855
{
856856
const struct VBDeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];

src/tinyformat.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -797,27 +797,27 @@ inline const char* streamStateFromFormat(std::ostream& out, bool& positionalMode
797797
break;
798798
case 'X':
799799
out.setf(std::ios::uppercase);
800-
// Falls through
800+
[[fallthrough]];
801801
case 'x': case 'p':
802802
out.setf(std::ios::hex, std::ios::basefield);
803803
intConversion = true;
804804
break;
805805
case 'E':
806806
out.setf(std::ios::uppercase);
807-
// Falls through
807+
[[fallthrough]];
808808
case 'e':
809809
out.setf(std::ios::scientific, std::ios::floatfield);
810810
out.setf(std::ios::dec, std::ios::basefield);
811811
break;
812812
case 'F':
813813
out.setf(std::ios::uppercase);
814-
// Falls through
814+
[[fallthrough]];
815815
case 'f':
816816
out.setf(std::ios::fixed, std::ios::floatfield);
817817
break;
818818
case 'A':
819819
out.setf(std::ios::uppercase);
820-
// Falls through
820+
[[fallthrough]];
821821
case 'a':
822822
# ifdef _MSC_VER
823823
// 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
829829
break;
830830
case 'G':
831831
out.setf(std::ios::uppercase);
832-
// Falls through
832+
[[fallthrough]];
833833
case 'g':
834834
out.setf(std::ios::dec, std::ios::basefield);
835835
// As in boost::format, let stream decide float format.

0 commit comments

Comments
 (0)