Skip to content

[Clang] Fix a regression introduced by #138518 #141342

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

Merged
merged 5 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13775,17 +13775,22 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
}

// Perform the initialization.
ParenListExpr *CXXDirectInit = dyn_cast<ParenListExpr>(Init);
bool InitializedFromParenListExpr = false;
bool IsParenListInit = false;
if (!VDecl->isInvalidDecl()) {
InitializedEntity Entity = InitializedEntity::InitializeVariable(VDecl);
InitializationKind Kind = InitializationKind::CreateForInit(
VDecl->getLocation(), DirectInit, Init);

MultiExprArg Args = Init;
if (CXXDirectInit)
Args = MultiExprArg(CXXDirectInit->getExprs(),
CXXDirectInit->getNumExprs());
if (auto *CXXDirectInit = dyn_cast<ParenListExpr>(Init)) {
Args =
MultiExprArg(CXXDirectInit->getExprs(), CXXDirectInit->getNumExprs());
InitializedFromParenListExpr = true;
} else if (auto *CXXDirectInit = dyn_cast<CXXParenListInitExpr>(Init)) {
Args = CXXDirectInit->getInitExprs();
InitializedFromParenListExpr = true;
}

// Try to correct any TypoExprs in the initialization arguments.
for (size_t Idx = 0; Idx < Args.size(); ++Idx) {
Expand Down Expand Up @@ -14083,10 +14088,9 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
// special case code.

// C++ 8.5p11:
// The form of initialization (using parentheses or '=') is generally
// insignificant, but does matter when the entity being initialized has a
// class type.
if (CXXDirectInit) {
// The form of initialization (using parentheses or '=') matters
// when the entity being initialized has class type.
if (InitializedFromParenListExpr) {
assert(DirectInit && "Call-style initializer must be direct init.");
VDecl->setInitStyle(IsParenListInit ? VarDecl::ParenListInit
: VarDecl::CallInit);
Expand Down
22 changes: 22 additions & 0 deletions clang/test/SemaCXX/paren-list-agg-init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,25 @@ void test() {
S<int>{}.f(); // beforecxx20-note {{requested here}}
}
}

namespace GH72880_regression {
struct E {
int i = 42;
};
struct G {
E e;
};
template <typename>
struct Test {
void f() {
constexpr E e;
//FIXME: We should only warn one
constexpr G g(e); // beforecxx20-warning 2{{C++20 extension}}
static_assert(g.e.i == 42);
}
};
void test() {
Test<int>{}.f(); // beforecxx20-note {{requested here}}
}

}
Loading