-
Notifications
You must be signed in to change notification settings - Fork 37.7k
build: Enable -Wsuggest-override if available #16710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: Enable -Wsuggest-override if available #16710
Conversation
Concept ACK -- consistent use of @hebasto Is this change complete in the sense that it addresses all instances of missing Note that |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
d6f5d89
to
f0e0a46
Compare
I did know that. Thank you. |
f0e0a46
to
6a8d284
Compare
Yes, it is (with the latest push). |
ACK 6a8d284 -- diff looks correct Thanks for making the change complete across the codebase. I think we should consider building with |
Concept ACK.
Why? Otherwise this may be necessary again right? |
@practicalswift @promag Thank you for your reviews.
How to skip warnings on |
True! If @hebasto wants to incorporate |
I tend to agree with @theuni regarding |
6a8d284
to
cf6bcb5
Compare
The latest push incorporates PR description has been updated. |
cf6bcb5
to
309bb12
Compare
Fixed MSVC build. |
309bb12
to
404c965
Compare
Fixed protobuf stuff. |
@practicalswift Would you mind re-reviewing this PR? |
404c965
to
695ad19
Compare
Rebased. |
Concept ACK. Not convinced about
NACK on WError of any kind by default. Feel free to enable it locally as a developer, but it is frustrating for packagers and people just trying to build the code, because changes in gcc version, dependency libraries and such frequently change the set of warnings. |
It seems there is a commit google/leveldb@28e6d23 to upstream related to
E.g., #15539. |
Nice, let's pull that in. It might be time to do a leveldb update from upstream anyhow for 0.20.
Yes, would agree those are silly. I guess we could disable specific warnings for leveldb, if there's no change of them being solved, I just dislike the idea of a blanket disable. |
Updated a96adef -> d44a13b (pr16710.14 -> pr16710.15):
I'd refrain from |
I don't think d44a13b is maintainable. How would devs with compilers that are not buggy figure out where to add the pragmas? I think the only thing that can be done is enable the warning for compilers that support it and skip it if the compiler does not support it fully and correctly. |
ACK d44a13b The current code contains just a few However, every addition of a new |
d44a13b
to
ea6849f
Compare
Updated d44a13b -> ea6849f (pr16710.15 -> pr16710.16, diff):
|
Done in the latest push. |
ea6849f
to
e6211d8
Compare
Updated ea6849f -> e6211d8 (pr16710.16 -> pr16710.17, diff):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK e6211d8
GCC 8.4.0:
checking for GCC version < 9.2... yes
configure: WARNING: GCC<9.2 reports a redundant -Wsuggest-override warning on a 'final' method, disabling -Wsuggest-override.
(and -Wsuggest-override -Werror=suggest-override
are not in CXXFLAGS
)
GCC 9.3.0:
checking for GCC version < 9.2... no
checking whether C++ compiler accepts -Werror=suggest-override... yes
checking whether C++ compiler accepts -Wsuggest-override... yes
Clang 11.0.0:
checking for GCC version < 9.2... no
checking whether C++ compiler accepts -Werror=suggest-override... no
checking whether C++ compiler accepts -Wsuggest-override... no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like this to replace the changes in configure.ac
:
diff --git a/configure.ac b/configure.ac
index 7de6adb93..31e9c243f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -368,6 +368,11 @@ if test "x$enable_werror" = "xyes"; then
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]])
AX_CHECK_COMPILE_FLAG([-Werror=sign-compare],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=sign-compare"],,[[$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([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
+ [AC_LANG_PROGRAM([[struct A { virtual void f(); };struct B : A { void f() final; };]])])
fi
if test "x$CXXFLAGS_overridden" = "xno"; then
@@ -385,6 +390,8 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
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([-Wsign-compare],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsign-compare"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
+ [AC_LANG_PROGRAM([[struct A { virtual void f(); };struct B : A { void f() final; };]])])
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
This way the check stays self-contained, no need to test version macros, no additional configure output and we can just use the source from the bug report.
e6211d8
to
839add1
Compare
@fanquake Thank you for your review. TIL :) Updated e6211d8 -> 839add1 (pr16710.17 -> pr16710.18, diff). |
ACK 839add1 assuming Travis is happy: patch looks correct |
ACK 839add1 Even better! I confirm it works as intended with GCC 8.4, 9.3 and Clang 11.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 839add1
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 bitcoin#16722 (the first commit).~ See: 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
Summary: refactor: Use override for non-final overriders 1551cea2d52cac403ff506a7cc955d8de8fd6f3e refactor: Remove override for final overriders d044e0ec7d37bbcdf10bbdb903b9119741c7297d > Two commits are split out from [[bitcoin/bitcoin#16710 | PR16710]] to make reviewing easier. > > From C++ FAQ: > > C.128: Virtual functions should specify exactly one of virtual, override, or final > Reason Readability. Detection of mistakes. Writing explicit virtual, override, or final is self-documenting and enables the compiler to catch mismatch of types and/or names between base and derived classes. However, writing more than one of these three is both redundant and a potential source of errors. This is a backport of Core [[bitcoin/bitcoin#18914 | PR18914]] Most of the work was done already in D767 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D9082
merge bitcoin#18914, bitcoin#13306, bitcoin#16424, bitcoin#13899, bitcoin#17486, bitcoin#17880, bitcoin#18145, bitcoin#18843, bitcoin#16710: split warnings out of CXXFLAGS, add more flags
Summary: This is a backport of [[bitcoin/bitcoin#16710 | core#16710]] [1/2] bitcoin/bitcoin@de5e91c This is backported out of order. In the original PR, it should have touched db.{h|c}, but the code was moved to bdb.{h|c} in D8615. The original PR includes only `db.h` in `rpcconsole.cpp`, and `bdb.h` should have been added additionaly in D8615 (both includes will be needed for subsequent backports (e.g. core#20202). Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10209
From GCC docs:
This PR is based on #16722 (the first commit).See: #16722 (comment)