[clang] [Clang] Fix a regression introduced by #138518 (PR #141342)
via cfe-commits
cfe-commits at lists.llvm.org
Sat May 24 03:47:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: cor3ntin (cor3ntin)
<details>
<summary>Changes</summary>
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
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}}
+}
+
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/141342
More information about the cfe-commits
mailing list