[clang] [Sema] Fix assertion in TreeTransform when rebuilding CXXParenListInitExpr (PR #203715)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 8 21:54:45 PDT 2026


https://github.com/arrowten updated https://github.com/llvm/llvm-project/pull/203715

>From 0e49d1fb2dfcd208beea16b4d47cc15742f65f6b Mon Sep 17 00:00:00 2001
From: Ajay Wakodikar <ajaywakodikarsocial at gmail.com>
Date: Sat, 13 Jun 2026 12:49:23 -0400
Subject: [PATCH] [Sema] Fix assertion in TreeTransform when rebuilding
 CXXParenListInitExpr

---
 clang/docs/ReleaseNotes.rst                          |  1 +
 clang/include/clang/AST/ExprCXX.h                    |  4 ++++
 clang/lib/Sema/TreeTransform.h                       |  3 ++-
 .../test/SemaCXX/paren-agg-init-template-rebuild.cpp | 12 ++++++++++++
 4 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/paren-agg-init-template-rebuild.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7828135a6edbc..f47928922b5f1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -706,6 +706,7 @@ Bug Fixes in This Version
 - Clang no longer handles a `" q-char-sequence "` header name as a string literal (#GH132643).
 - Fixed an assertion when ``__attribute__((alloc_size))`` is used with an argument type wider than the target's pointer width. (#GH190445)
 - Fixed an assertion where we improperly handled implicit conversions to integral types from an atomic-type with a conversion function. (#GH201770)
+- Fixed an assertion when rebuilding a ``CXXParenListInitExpr`` during template instantiation of parenthesized aggregate initialization. (#GH194986)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 36e5f8940228e..28ab1b7aa6d52 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5184,6 +5184,10 @@ class CXXParenListInitExpr final
 
   ArrayRef<Expr *> getInitExprs() const { return getTrailingObjects(NumExprs); }
 
+  MutableArrayRef<Expr *> getUserSpecifiedInitExprs() {
+    return getTrailingObjects(NumUserSpecifiedExprs);
+  }
+
   ArrayRef<Expr *> getUserSpecifiedInitExprs() const {
     return getTrailingObjects(NumUserSpecifiedExprs);
   }
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 53107c827006d..8b61074d9db85 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -3412,7 +3412,8 @@ class TreeTransform {
 
     if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
       return getSema().BuildCXXTypeConstructExpr(
-          TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization);
+          TInfo, LParenLoc, PLE->getUserSpecifiedInitExprs(), RParenLoc,
+          ListInitialization);
 
     return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
                                                MultiExprArg(&Sub, 1), RParenLoc,
diff --git a/clang/test/SemaCXX/paren-agg-init-template-rebuild.cpp b/clang/test/SemaCXX/paren-agg-init-template-rebuild.cpp
new file mode 100644
index 0000000000000..9ac9d9fe797bb
--- /dev/null
+++ b/clang/test/SemaCXX/paren-agg-init-template-rebuild.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -verify -std=c++23 %s -fsyntax-only
+
+struct S {}; // expected-note 2{{candidate constructor}}
+template <typename T> struct SS { T t1; T t2; };
+template <class T, class... Args> T C(Args... args) { return SS("foo"); } // expected-error {{no viable conversion}}
+S s = C<S>(); // expected-note {{in instantiation of function template specialization 'C<S>'}}
+
+template <class T> struct SS2 { T t1, t2; };
+template <class> void C2() {
+  SS2("foo"); // expected-warning 2{{expression result unused}}
+}
+template void C2<int>(); // expected-note {{in instantiation of function template specialization 'C2<int>'}}



More information about the cfe-commits mailing list