[clang-tools-extra] [clang-tidy][C++20] Add support for Initialization Forwarding in structs and Nested Objects within modernize-use-emplace (PR #131969)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 13 23:49:07 PDT 2025
================
@@ -332,19 +376,42 @@ void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
}();
assert(Call && "No call matched");
- assert((CtorCall || MakeCall) && "No push_back parameter matched");
+ assert((CtorCall || MakeCall || AggInitCall) &&
+ "No push_back parameter matched");
if (IgnoreImplicitConstructors && CtorCall && CtorCall->getNumArgs() >= 1 &&
CtorCall->getArg(0)->getSourceRange() == CtorCall->getSourceRange())
return;
+ if (IgnoreImplicitConstructors && AggInitCall &&
+ AggInitCall->getNumInits() >= 1 &&
+ AggInitCall->getInit(0)->getSourceRange() ==
+ AggInitCall->getSourceRange())
+ return;
+
+ if (getLangOpts().LangStd >= LangStandard::lang_cxx20 && AggInitCall) {
+ for (const auto *Init : AggInitCall->inits()) {
+ if (const auto *InnerConstructorExpr = unwrapToConstructorExpr(Init)) {
+ // consume all args if it's an empty constructor call so that we can ->
+ // T{} -> emplace_back()
+ if (InnerConstructorExpr && InnerConstructorExpr->getNumArgs() == 0) {
----------------
vbvictor wrote:
```suggestion
if (InnerConstructorExpr->getNumArgs() == 0) {
```
No need to check that `InnerConstructorExpr` is not null here because it's done in previous `if`
https://github.com/llvm/llvm-project/pull/131969
More information about the cfe-commits
mailing list