Skip to content

Commit b46fb5c

Browse files
committed
Merge #19131: refactor: Fix unreachable code in init arg checks
eea8114 build: Enable unreachable-code-loop-increment (Jonathan Schoeller) d15db4b refactor: Fix unreachable code in init arg checks (Jonathan Schoeller) Pull request description: 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. ```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/bitcoin#19131 (review)) review. Tree-SHA512: 2aa3ceb7fab581b6ba2580900668388d8eba1c3001c8ff9c11c1f4a9a10fbc37f30e590249862676858446e3f4950140a252953ba1643ba3bfd772f8eae20583
2 parents 584170a + eea8114 commit b46fb5c

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ if test "x$enable_werror" = "xyes"; then
391391
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78010
392392
AX_CHECK_COMPILE_FLAG([-Werror=suggest-override],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=suggest-override"],,[[$CXXFLAG_WERROR]],
393393
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
394+
AX_CHECK_COMPILE_FLAG([-Werror=unreachable-code-loop-increment],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
394395
fi
395396

396397
if test "x$CXXFLAGS_overridden" = "xno"; then
@@ -410,6 +411,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
410411
AX_CHECK_COMPILE_FLAG([-Wsign-compare],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsign-compare"],,[[$CXXFLAG_WERROR]])
411412
AX_CHECK_COMPILE_FLAG([-Wsuggest-override],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wsuggest-override"],,[[$CXXFLAG_WERROR]],
412413
[AC_LANG_SOURCE([[struct A { virtual void f(); }; struct B : A { void f() final; };]])])
414+
AX_CHECK_COMPILE_FLAG([-Wunreachable-code-loop-increment],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wunreachable-code-loop-increment"],,[[$CXXFLAG_WERROR]])
413415

414416
dnl Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
415417
dnl unknown options if any other warning is produced. Test the -Wfoo case, and

src/init.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,17 +964,27 @@ bool AppInitParameterInteraction()
964964

965965
// also see: InitParameterInteraction()
966966

967-
// Warn if network-specific options (-addnode, -connect, etc) are
967+
// Error if network-specific options (-addnode, -connect, etc) are
968968
// specified in default section of config file, but not overridden
969969
// on the command line or in this network's section of the config file.
970970
std::string network = gArgs.GetChainName();
971+
bilingual_str errors;
971972
for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) {
972-
return InitError(strprintf(_("Config setting for %s only applied on %s network when in [%s] section."), arg, network, network));
973+
errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network);
974+
}
975+
976+
if (!errors.empty()) {
977+
return InitError(errors);
973978
}
974979

975980
// Warn if unrecognized section name are present in the config file.
981+
bilingual_str warnings;
976982
for (const auto& section : gArgs.GetUnrecognizedSections()) {
977-
InitWarning(strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized."), section.m_file, section.m_line, section.m_name));
983+
warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.") + Untranslated("\n"), section.m_file, section.m_line, section.m_name);
984+
}
985+
986+
if (!warnings.empty()) {
987+
InitWarning(warnings);
978988
}
979989

980990
if (!fs::is_directory(GetBlocksDir())) {

src/util/translation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ struct bilingual_str {
2323
translated += rhs.translated;
2424
return *this;
2525
}
26+
27+
bool empty() const
28+
{
29+
return original.empty();
30+
}
2631
};
2732

2833
inline bilingual_str operator+(bilingual_str lhs, const bilingual_str& rhs)

test/functional/feature_config_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_config_file_parser(self):
7171
with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
7272
conf.write('[testnet]\n')
7373
self.restart_node(0)
74-
self.nodes[0].stop_node(expected_stderr='Warning: ' + inc_conf_file_path + ':1 Section [testnot] is not recognized.' + os.linesep + 'Warning: ' + inc_conf_file2_path + ':1 Section [testnet] is not recognized.')
74+
self.nodes[0].stop_node(expected_stderr='Warning: ' + inc_conf_file_path + ':1 Section [testnot] is not recognized.' + os.linesep + inc_conf_file2_path + ':1 Section [testnet] is not recognized.')
7575

7676
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
7777
conf.write('') # clear

0 commit comments

Comments
 (0)