https://github.com/IvyXu420 created 
https://github.com/llvm/llvm-project/pull/228340

Fixes #226485 and #181448.

When a template is instantiated, `TreeTransform` rebuilds the expression via 
`RebuildCXXFunctionalCastExpr`, which uses `E->isListInitialization()` (i.e. 
`LParenLoc.isInvalid()`) to decide whether the expression models 
list-initialization.

Mark `void{}` as list-initialization by passing an invalid `LParenLoc` in 
`BuildCXXTypeConstructExpr`, so it is not rebuilt
as `void({})`.

Assisted-by: Claude Sonnet 5.5.

>From e18bacfeed81a1cf3cd085a88e34ee359079c54d Mon Sep 17 00:00:00 2001
From: Ivy Xu <[email protected]>
Date: Fri, 2 Oct 2026 03:38:40 +0800
Subject: [PATCH 1/2] Fix clang rejecting valid `void{}` when template is used

---
 clang/lib/Sema/SemaExprCXX.cpp | 2 +-
 clang/test/CXX/drs/cwg23xx.cpp | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 1bf6430665ddf..1ed58fcf20af0 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1647,7 +1647,7 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
       return CXXFunctionalCastExpr::Create(
           Context, Ty.getUnqualifiedType(), VK_PRValue, TInfo, CK_ToVoid,
           Exprs[0], /*Path=*/nullptr, CurFPFeatureOverrides(),
-          Exprs[0]->getBeginLoc(), Exprs[0]->getEndLoc());
+          SourceLocation(), Exprs[0]->getEndLoc());
     }
   } else if (RequireCompleteType(TyBeginLoc, ElemTy,
                                  diag::err_invalid_incomplete_type_use,
diff --git a/clang/test/CXX/drs/cwg23xx.cpp b/clang/test/CXX/drs/cwg23xx.cpp
index cfd78465c0dbe..c81fe223a596c 100644
--- a/clang/test/CXX/drs/cwg23xx.cpp
+++ b/clang/test/CXX/drs/cwg23xx.cpp
@@ -240,6 +240,10 @@ namespace cwg2351 { // cwg2351: 20
   template void i<void>();
   template const void i<const void>();
 
+  template <class T>
+  void f(T) { void{}; }
+  void g() { f(1); }
+
   static_assert((void({}), true), "");
   // since-cxx11-error@-1 {{cannot initialize non-class type 'void' with a 
parenthesized initializer list}}
 #else

>From 71dd64f2aa5951756198f7ad7a99bd1ab851be3a Mon Sep 17 00:00:00 2001
From: Ivy Xu <[email protected]>
Date: Fri, 2 Oct 2026 14:25:05 +0800
Subject: [PATCH 2/2] Add release note

---
 clang/docs/ReleaseNotes.md | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index d22874d4130ee..04ded7c5b6a2e 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -801,6 +801,9 @@ features cannot lower the translation-unit ABI level;
   take effect, causing them to be dropped from llvm.used and omitted from
   the object file. (#GH226572)
 
+- Fixed rejection of non-dependent `void{}` during template instantiation,
+  which previously rebuilt the expression as `void({})`. (#GH226485, #GH181448)
+
 #### Bug Fixes to AST Handling
 
 - Fixed a non-deterministic ordering of unused local typedefs that made

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to