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

via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 29 01:51:10 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

<details>
<summary>Changes</summary>

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

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaType.cpp (+3) 
- (modified) clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp (+12) 


``````````diff
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>

``````````

</details>


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


More information about the cfe-commits mailing list