Skip to content

Commit c060345

Browse files
committed
[Clang] Fix a regression introduced by #138518
We did not handle the case where a variable could be initialized by a CXXParenListInitExpr.
1 parent af2a957 commit c060345

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13783,9 +13783,11 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
1378313783
VDecl->getLocation(), DirectInit, Init);
1378413784

1378513785
MultiExprArg Args = Init;
13786-
if (CXXDirectInit)
13787-
Args = MultiExprArg(CXXDirectInit->getExprs(),
13788-
CXXDirectInit->getNumExprs());
13786+
if (auto *CXXDirectInit = dyn_cast<ParenListExpr>(Init))
13787+
Args =
13788+
MultiExprArg(CXXDirectInit->getExprs(), CXXDirectInit->getNumExprs());
13789+
else if (auto *CXXDirectInit = dyn_cast<CXXParenListInitExpr>(Init))
13790+
Args = CXXDirectInit->getInitExprs();
1378913791

1379013792
// Try to correct any TypoExprs in the initialization arguments.
1379113793
for (size_t Idx = 0; Idx < Args.size(); ++Idx) {

clang/test/SemaCXX/paren-list-agg-init.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,25 @@ void test() {
403403
S<int>{}.f(); // beforecxx20-note {{requested here}}
404404
}
405405
}
406+
407+
namespace GH72880_regression {
408+
struct E {
409+
int i = 42;
410+
};
411+
struct G {
412+
E e;
413+
};
414+
template <typename>
415+
struct Test {
416+
void f() {
417+
constexpr E e;
418+
//FIXME: We should only warn one
419+
constexpr G g(e); // beforecxx20-warning 2{{C++20 extension}}
420+
static_assert(g.e.i == 42);
421+
}
422+
};
423+
void test() {
424+
Test<int>{}.f(); // beforecxx20-note {{requested here}}
425+
}
426+
427+
}

0 commit comments

Comments
 (0)