Skip to content

util: Catch translation string errors at compile time - #30383

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
maflcko:2407-trans
Jul 11, 2024
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
maflcko:2407-trans

Conversation

@maflcko

@maflcko maflcko commented Jul 3, 2024

Copy link
Copy Markdown
Member

The translation helper function _() has many problems. For example, the following compiles:

auto ptr{"wrong"};
_(ptr);
_(nullptr);
_(0);
_(NULL);

However, it is wrong, because none of the arguments passed to the function can be picked up by the translation tooling for transifex.

Fix all issues by enforcing only real string literals can be passed to the function.

@DrahtBot

DrahtBot commented Jul 3, 2024 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky, hebasto

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@maflcko

maflcko commented Jul 3, 2024

Copy link
Copy Markdown
Member Author

Can be tested by looking at the CI failure, which should pop up soon, or by manually inserting the C++ code from the pull request description.

@fanquake

fanquake commented Jul 3, 2024

Copy link
Copy Markdown
Member
  CXX      test/fuzz/fuzz-string.o
  CXX      libbitcoin_node_a-validation.o
test/fuzz/string.cpp:104:13: error: call to consteval function 'ConstevalStringLiteral::ConstevalStringLiteral' is not a constant expression
    (void)_(random_string_1.c_str());
1 error generated.

validation.cpp:5750:30: error: call to consteval function 'ConstevalStringLiteral::ConstevalStringLiteral' is not a constant expression
        return util::Error{_(reason)};
                             ^
validation.cpp:5750:30: note: function parameter 'reason' with unknown value cannot be used in a constant expression
validation.cpp:5734:49: note: declared here
    auto cleanup_bad_snapshot = [&](const char* reason) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
                                                ^
1 error generated.

@hebasto

hebasto commented Jul 3, 2024

Copy link
Copy Markdown
Member

Concept ACK on the PR's goal.

@DrahtBot

DrahtBot commented Jul 5, 2024

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/27075181532

@maflcko
maflcko marked this pull request as ready for review July 10, 2024 07:39
@maflcko

maflcko commented Jul 10, 2024

Copy link
Copy Markdown
Member Author

Rebased to drop merged commit.

Current CI failure is unrelated and can be ignored.

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK fa601ab

@DrahtBot
DrahtBot requested a review from hebasto July 10, 2024 14:03

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa601ab.

nit: The error messages for the cases _(0); and _(NULL); can be confusing a bit. For instance, clang-18 reports "conversion from 'long' to 'ConstevalStringLiteral' is ambiguous" for the latter.

@maflcko

maflcko commented Jul 10, 2024

Copy link
Copy Markdown
Member Author

nit: The error messages for the cases _(0); and _(NULL); can be confusing a bit. For instance, clang-18 reports "conversion from 'long' to 'ConstevalStringLiteral' is ambiguous" for the latter.

Unrelated to this codebase, but I'd say this should be fixed upstream by doing #define NULL nullptr (under C++11 or later) instead of using an integer literal.

@fanquake
fanquake merged commit a231cfe into bitcoin:master Jul 11, 2024
@maflcko
maflcko deleted the 2407-trans branch July 12, 2024 09:19
@bitcoin bitcoin locked and limited conversation to collaborators Jul 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants