[clang] [Clang] Ensure the instantiation of array initializers for decltype/_typeof operator (PR #133575)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 29 01:50:36 PDT 2025


https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/133575

This is a follow-up to a9672515ce, per Richard's suggestion we should ensure the instantiation for these unevaluated operators as well.

No release entry because the issue being fixed was already claimed resolved in that patch (though not intended).

Fixes https://github.com/llvm/llvm-project/issues/79750

>From 1100d56138a09a850aed4857ee69bffcff10fc6d Mon Sep 17 00:00:00 2001
From: Younan Zhang <zyn7109 at gmail.com>
Date: Sat, 29 Mar 2025 16:42:12 +0800
Subject: [PATCH] [Clang] Ensure the instantiation of array initializers for
 decltype/__typeof operator

This is a follow-up to a9672515ce, per Richard's suggestion we should
ensure the instantiation for these unevaluated operators as well.

No release entry because the issue being fixed was already claimed
resolved in that patch (though not intended).
---
 clang/lib/Sema/SemaType.cpp                          |  3 +++
 .../SemaCXX/cxx1y-variable-templates_top_level.cpp   | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 776d6e55acc18..4b1a44d378f38 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9544,6 +9544,7 @@ QualType Sema::BuildTypeofExprType(Expr *E, TypeOfKind Kind) {
     QualType T = E->getType();
     if (const TagType *TT = T->getAs<TagType>())
       DiagnoseUseOfDecl(TT->getDecl(), E->getExprLoc());
+    getCompletedType(E);
   }
   return Context.getTypeOfExprType(E, Kind);
 }
@@ -9589,6 +9590,8 @@ QualType Sema::getDecltypeForExpr(Expr *E) {
   if (E->isTypeDependent())
     return Context.DependentTy;
 
+  getCompletedType(IDExpr);
+
   // C++11 [dcl.type.simple]p4:
   //   The type denoted by decltype(e) is defined as follows:
 
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
index 6fc2032ee7fb4..7fcc688d7fd1b 100644
--- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -472,6 +472,18 @@ namespace VexingParse {
 
 namespace GH79750 {
 
+template <unsigned...values>
+constexpr unsigned array[]{ values... };
+
+// Test if the unevaluated operators trigger instantiation of the array initializer.
+static_assert(__is_same(__typeof(array<1, 2, 3, 4, 5>),  const unsigned[5]), "");
+
+static_assert(__is_same(decltype(array<1, 2, 3, 4>),  const unsigned[4]), "");
+
+}
+
+namespace GH79750_2 {
+
 enum class Values { A };
 
 template<typename E>



More information about the cfe-commits mailing list