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

Conversation

cor3ntin
Copy link
Contributor

We did not handle the case where a variable could be initialized by a CXXParenListInitExpr.

@cor3ntin cor3ntin requested review from alexfh and erichkeane May 24, 2025 10:47
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 24, 2025
@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)

Changes

We did not handle the case where a variable could be initialized by a CXXParenListInitExpr.


Full diff: https://github.com/llvm/llvm-project/pull/141342.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDecl.cpp (+5-3)
  • (modified) clang/test/SemaCXX/paren-list-agg-init.cpp (+22)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 90525f386468a..41eb7c797b37d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13783,9 +13783,11 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
         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());
+    else if (auto *CXXDirectInit = dyn_cast<CXXParenListInitExpr>(Init))
+        Args = CXXDirectInit->getInitExprs();
 
     // Try to correct any TypoExprs in the initialization arguments.
     for (size_t Idx = 0; Idx < Args.size(); ++Idx) {
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp b/clang/test/SemaCXX/paren-list-agg-init.cpp
index ba7dffdc1af9f..680fdcdbe7b1c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -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}}
+}
+
+}

Copy link

github-actions bot commented May 24, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

We did not handle the case where a variable could be
initialized by a CXXParenListInitExpr.
@cor3ntin cor3ntin force-pushed the corentin/fix_gh138518_regression branch from 987c1f5 to c060345 Compare May 24, 2025 10:55
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

1 nit, else lgtm.

if (CXXDirectInit)
Args = MultiExprArg(CXXDirectInit->getExprs(),
CXXDirectInit->getNumExprs());
if (auto *CXXDirectInit = dyn_cast<ParenListExpr>(Init))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we remove line 13778 now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good catch

Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
@cor3ntin cor3ntin merged commit 5c063be into llvm:main May 28, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants