refactor: Fix unreachable code in init arg checks#19131
refactor: Fix unreachable code in init arg checks#19131laanwj merged 2 commits intobitcoin:masterfrom
Conversation
|
Concept ACK: thanks for fixing this and thereby allowing us to catch more severe issues using Great first time contribution and great rationale section in the PR description. Warm welcome as a contributor @jonathanschoeller! :) |
maflcko
left a comment
There was a problem hiding this comment.
Nice. ACK with or without the nit addressed
|
Oh, it looks like you might have to adjust the tests for the longer error messages. |
|
Concept ACK. |
34c4fc9 to
b546870
Compare
src/init.cpp
Outdated
There was a problem hiding this comment.
please don't change the translation string _("Section [%s] is not recognized.") and keep the special character \n untranslated (like above)
There was a problem hiding this comment.
ACK b546870d178222acd5d3f131410b8846f4875412, tested on Linux Mint 19.3 (x86_64).
I suggest to add a commit to modify configure.ac as well:
--- a/configure.ac
+++ b/configure.ac
@@ -391,6 +391,7 @@ if test "x$enable_werror" = "xyes"; then
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; };]])])
+ AX_CHECK_COMPILE_FLAG([-Werror=unreachable-code-loop-increment],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
fi
if test "x$CXXFLAGS_overridden" = "xno"; then
@@ -410,6 +411,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
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_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]])
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
src/init.cpp
Outdated
There was a problem hiding this comment.
| warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.\n"), section.m_file, section.m_line, section.m_name); | |
| warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.") + Untranslated("\n"), section.m_file, section.m_line, section.m_name); |
Building with -Wunreachable-code-loop-increment causes a warning due to always returning on the first iteration of the loop that outputs errors on invalid args. Collect all errors, and output them in a single error message after the loop completes, resolving the warning and avoiding popup hell by outputting a seperate message for each error.
Enable unreachable-code-loop-increment and treat as error. refs: bitcoin#19015
b546870 to
eea8114
Compare
|
Thanks @practicalswift , @MarcoFalke , and @hebasto for welcoming me and taking the time to help me with this PR. |
|
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. |
|
Code review ACK eea8114 |
eea8114 build: Enable unreachable-code-loop-increment (Jonathan Schoeller) d15db4b refactor: Fix unreachable code in init arg checks (Jonathan Schoeller) Pull request description: Closes: bitcoin#19017 In bitcoin#19015 it's been suggested that we add some new compiler warnings to our build. Some of these, such as `-Wunreachable-code-loop-increment`, generate warnings. We'll likely want to fix these up if we're going to turn these warnings on. ```shell init.cpp:969:5: warning: loop will run at most once (loop increment never executed) [-Wunreachable-code-loop-increment] for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) { ^~~ 1 warning generated. ``` https://github.com/bitcoin/bitcoin/blob/aa8d76806c74a51ec66e5004394fe9ea8ff0fac4/src/init.cpp#L968-L972 To fix this, collect all errors, and output them in a single error message after the loop completes. This resolves the unreachable code warning, and avoids popup hell that could result from outputting a seperate message for each error or warning one by one. ACKs for top commit: laanwj: Code review ACK eea8114 hebasto: re-ACK eea8114, only suggested changes applied since the [previous](bitcoin#19131 (review)) review. Tree-SHA512: 2aa3ceb7fab581b6ba2580900668388d8eba1c3001c8ff9c11c1f4a9a10fbc37f30e590249862676858446e3f4950140a252953ba1643ba3bfd772f8eae20583
Summary: Backport of core [[bitcoin/bitcoin#19131 | PR19131]]. Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D8648
Summary: Follow-up for rABC6c84fca7a26eee3f5f031f02610d4528f7ef8276 which lost the changes for an unknown reason. Backport of core [[bitcoin/bitcoin#19131 | PR19131]]. Test Plan: With Werror enabled: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D8658
Closes: #19017
In #19015 it's been suggested that we add some new compiler warnings to our build. Some of these, such as
-Wunreachable-code-loop-increment, generate warnings. We'll likely want to fix these up if we're going to turn these warnings on.init.cpp:969:5: warning: loop will run at most once (loop increment never executed) [-Wunreachable-code-loop-increment] for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) { ^~~ 1 warning generated.bitcoin/src/init.cpp
Lines 968 to 972 in aa8d768
To fix this, collect all errors, and output them in a single error message after the loop completes. This resolves the unreachable code warning, and avoids popup hell that could result from outputting a seperate message for each error or warning one by one.