-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: [tidy] modernize-use-emplace #28583
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
refactor: [tidy] modernize-use-emplace #28583
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
Concept ACK. |
Can we do something with code like that: Line 325 in db7b5df
(however, not related to this PR changes) |
No. |
fa59833
to
dddd734
Compare
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 dddd734, I've followed clang-tidy's warnings locally.
In your opinion, which value of the IgnoreImplicitConstructors
options is better/safer for us?
Not sure why that option exists. Edit: Looking at the tests (clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace-ignore-implicit-constructors.cpp) and the documentation, I could not figure out the use case. Unrelated: An emplace function is able to call explicit constructors, even though they won't be spelled out explicitly in the source code. A push function is not able to call explicit constructors. However, if the code compiles with a push function, it should also compile with an emplace function. |
Concept ACK |
utACK dddd734
Someone on the internet says that this ability to call explicit constructors can sometimes lead to bugs. But since everything here was first compiled with |
@hebasto For reference, I edited my previous replies. I realized that |
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 dddd734
Jup, this should only affect new code. Other things to consider: Named args and designated initializers won't be possible with emplace. Also: Theoretically there could be resource leak, when using src/test/denialofservice_tests.cpp: vNodes.emplace_back(new CNode{id++,
src/test/fuzz/coinscache_sim.cpp: caches.emplace_back(new CCoinsViewCache(&bottom, /*deterministic=*/true));
src/test/fuzz/coinscache_sim.cpp: caches.emplace_back(new CCoinsViewCache(&*caches.back(), /*deterministic=*/true)); |
fa3c80c
to
fa2876c
Compare
rebased for clang-17. Excluded nanobench for now due to it being C++11, but here it is compiled as C++17, also clang-tidy-17 introduced a new rule that requires C++20. 🥲 Should be trivial to re-ACK. |
I guess the only way to fix the CI failure would be:
|
Example of the CI error:
Is there an upstream issue? |
fa2876c
to
fac590b
Compare
Just recalled that |
fac590b
to
fa05a72
Compare
re-utACK fa05a72 |
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 fa05a72.
"src/bench/nanobench.cpp", | ||
"src/bench/nanobench.h", |
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.
nit: They might be ordered lexicographically?
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 fa05a72
Constructing a temporary unnamed object only to copy or move it into a container seems both verbose in code and a strict performance penalty.
Fix both issues via the
modernize-use-emplace
tidy check.