The changes are required for #31061, however they also make sense on their own. For example, they are fixing up an inline namespace, which lead to compile errors otherwise (can be tested by observing the compile error after reverting the changes to src/util/strencodings.h). Also, a unit test comment is fixed.
refactor: Prepare compile-time check of bilingual format strings #31295
pull maflcko wants to merge 3 commits into bitcoin:master from maflcko:2411-trans-fmt-prepare changing 9 files +113 −108-
maflcko commented at 4:37 PM on November 15, 2024: member
-
faff8403f0
refactor: Pick translated string after format
This passes the return value of _() directly to strprintf so the format string can be checked at compile time in a future commit.
-
fa72646f2b
move-only: Detail_CheckNumFormatSpecifiers and G_TRANSLATION_FUN
This is required for a future commit. Can be reviewed via the git options --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space Also move util::detail::Hex to a proper namespace instead of an inline namespace so it doesn't conflict with the new util::detail namespace, and won't create other problems for callers trying to use the inline namespaces. Also fix a misleading comment in util_string_tests.cpp. Co-Authored-By: Ryan Ofsky <ryan@ofsky.org>
-
fa3e074304
refactor: Tidy fixups
Requested by clang-tidy: src/wallet/salvage.cpp:119:18: error: use emplace_back instead of push_back [modernize-use-emplace,-warnings-as-errors] 119 | warnings.push_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable.")); | ^~~~~~~~~~ | emplace_back( -
DrahtBot commented at 4:37 PM on November 15, 2024: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
Code Coverage & Benchmarks
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31295.
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline for information on the review process.
Type Reviewers ACK ryanofsky, l0rinc, hodlinator If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #31260 (scripted-diff: Type-safe settings retrieval by ryanofsky)
- #30933 (test: Prove+document ConstevalFormatString/tinyformat parity by hodlinator)
- #26022 (Add util::ResultPtr class by ryanofsky)
- #25665 (refactor: Add util::Result failure values, multiple error and warning messages by ryanofsky)
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.
- DrahtBot added the label Refactoring on Nov 15, 2024
- ryanofsky approved
-
ryanofsky commented at 2:37 PM on November 18, 2024: contributor
Code review ACK fa3e074304780549b1e7972217930e34fa55f59a. Nice changes! These should allow related PRs to be simpler.
- maflcko requested review from stickies-v on Nov 20, 2024
- maflcko requested review from l0rinc on Nov 21, 2024
-
in src/wallet/feebumper.cpp:27 in fa3e074304
23 | @@ -24,24 +24,24 @@ namespace wallet { 24 | static feebumper::Result PreconditionChecks(const CWallet& wallet, const CWalletTx& wtx, bool require_mine, std::vector<bilingual_str>& errors) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) 25 | { 26 | if (wallet.HasWalletSpend(wtx.tx)) { 27 | - errors.push_back(Untranslated("Transaction has descendants in the wallet")); 28 | + errors.emplace_back(Untranslated("Transaction has descendants in the wallet"));
l0rinc commented at 10:44 AM on November 21, 2024:I tried reproducing the tidy warnings with
$ clang++ --version Homebrew clang version 19.1.3 $ cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ && cmake --build build -j$(nproc) \ && run-clang-tidy -p build -j$(nproc) -checks='-*,modernize-use-emplace' src/wallet/feebumper.cppBut it doesn't give me the mentioned warnings. The change itself does make sense (forwarding the bilingual_str params directly), I just can't seem to reproduce the warning. Based on https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-emplace.html the check targets cases where a temporary object is explicitly constructed in the argument to push_back. Was this different in the original PR, where the construction happened inside of push_back (or related to any of the warnings below) or am I running something incorrectly?
Enabling all warnings for this file I do see a few other ones, some of them may be related to translations, e.g.
bitcoin/src/wallet/feebumper.cpp:27:26: error: 'Untranslated' must resolve to a function declared within the namespace defined by the 'LIBC_NAMESPACE' macro [llvmlibc-callee-namespace,-warnings-as-errors] 27 | errors.push_back(Untranslated("Transaction has descendants in the wallet")); | ^ bitcoin/src/util/translation.h:51:22: note: resolves to this declaration 51 | inline bilingual_str Untranslated(std::string original) { return {original, original}; } | ^and
bitcoin/src/wallet/feebumper.cpp:49:26: error: 'format<std::string, std::string>' must resolve to a function declared within the namespace defined by the 'LIBC_NAMESPACE' macro [llvmlibc-callee-namespace,-warnings-as-errors] 49 | errors.push_back(strprintf(Untranslated("Cannot bump transaction %s which was already bumped by transaction %s"), wtx.GetHash().ToString(), wtx.mapValue.at("replaced_by_txid"))); | ^ bitcoin/src/tinyformat.h:1165:19: note: expanded from macro 'strprintf' 1165 | #define strprintf tfm::format | ^ bitcoin/src/util/translation.h:56:15: note: resolves to this declaration 56 | bilingual_str format(const bilingual_str& fmt, const Args&... args) | ^
nit, shouldn't
Untranslatedpass by const reference instead (or nobody cares since it's inline anyway), i.e.inline bilingual_str Untranslated(const std::string& original) { return {original, original}; }?
maflcko commented at 12:04 PM on November 21, 2024:I don't think it matters either way in practise, because
std::stringcan be moved so cheaply that an elided temporary won't be noticed one way or another. This commit is just taken from the other pulls, so that clang-tidy is happy with them.
l0rinc commented at 12:08 PM on November 21, 2024:Can you reproduce the warning in this PR? If not, what's the reason for the warning in other PRs (and not here). If you can, what was I doing wrong?
maflcko commented at 12:34 PM on November 21, 2024:It shouldn't reproduce. This commit is just taken from the other pulls, so that clang-tidy is happy with them.
Edit: (resolving for now)
l0rinc approvedl0rinc commented at 11:57 AM on November 21, 2024: contributorACK fa3e074304780549b1e7972217930e34fa55f59a
Lots of versions for this change, loosely coupled, but I understand they will simplify follow-ups. I have validated manually that:
run-lint-format-strings.pystill needs the exception 👍- all code moves are same as before 👍
- tidy warns for
feebumper.cpp,salvage.cppandwallet.cpp👎 (couldn't reproduce any of them, but manually checked it and at least it shouldn't be worse than before)
maflcko requested review from hodlinator on Dec 4, 2024hodlinator approvedhodlinator commented at 2:28 PM on December 4, 2024: contributorcr-ACK fa3e074304780549b1e7972217930e34fa55f59a
Before
strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR)- Create a
bilingual_strof"Copyright (C) %i-%i".- Calls
G_TRANSLATION_FUN("Copyright (C) %i-%i"), getting something like"Szerzői jog (c) %i-%i", and storing it in.translated.
- Calls
- Perform regular
strprintf()(tfm::format(std::string...)) on the returned.translatedand substitute in the values, yielding"Szerzői jog (c) 2009-2024".
After
strprintf(_("Copyright (C) %i-%i"), 2009, COPYRIGHT_YEAR).translated- Create a
bilingual_strof"Copyright (C) %i-%i".- Calls
G_TRANSLATION_FUN("Copyright (C) %i-%i"), getting something like"Szerzői jog (c) %i-%i", and storing it in.translated.
- Calls
- Perform special
strprintf()(tfm::format(bilingual_str...)).tfm::formatcall for the.originalstring.- Checks each
argstype, and forbilingual_strit fetches the.originalvalue for that arg.
- Checks each
tfm::formatfor the.translatedstring.- Checks each
argstype, and forbilingual_strit fetches the.translatedvalue for that arg.
- Checks each
- Fetch the
.translatedhalf of thestrprintf-result containing"Szerzői jog (c) 2009-2024"(throwing away the work from 2.i,"Copyright (C) 2009-2024").
End result is that we do slightly more work at runtime. Translation-strings themselves should not be affected.
This makes me disagree with the PR summary that the
.translatedchanges in faff8403f0aac3b5ec26d3c7fc98240f879f9906 "make sense on their own" without #31061. But I'm reasonably confident that PR will be merged after having reviewed it as well.ryanofsky assigned ryanofsky on Dec 4, 2024ryanofsky merged this on Dec 4, 2024ryanofsky closed this on Dec 4, 2024maflcko deleted the branch on Dec 4, 2024sedited referenced this in commit 230a439a4a on Jan 17, 2025stickies-v referenced this in commit d760fd3dda on Mar 17, 2025stickies-v referenced this in commit cc83553352 on Mar 17, 2025stickies-v referenced this in commit 2614933f06 on Mar 17, 2025stickies-v referenced this in commit b70418c5fc on Mar 17, 2025stickies-v referenced this in commit 69f8a1fe50 on Mar 17, 2025bug-castercv502 referenced this in commit 44b075fe71 on Sep 28, 2025bitcoin locked this on Dec 4, 2025
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 18:13 UTC
More mirrored repositories can be found on mirror.b10c.me