Skip to content

Conversation

@zyn0217
Copy link
Contributor

@zyn0217 zyn0217 commented Mar 29, 2025

This is a follow-up to a967251, 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 #79750

…_typeof operator This is a follow-up to a967251, 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).
@zyn0217 zyn0217 requested review from cor3ntin and zygoloid March 29, 2025 08:50
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 29, 2025

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

Changes

This is a follow-up to a967251, 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 #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 --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> 
@cor3ntin
Copy link
Contributor

I find myself wanting a RequireCompleteType (or just CompletesType - maybe with asserts that check that the resulting types is indeed complete) overload that does not take a diagnostic. getCompletedType does not make it clear what it does. And comments would help

@zyn0217
Copy link
Contributor Author

zyn0217 commented Mar 29, 2025

I find myself wanting a RequireCompleteType (or just CompletesType - maybe with asserts that check that the resulting types is indeed complete) overload that does not take a diagnostic. getCompletedType does not make it clear what it does. And comments would help

Humm, I didn't use RequireCompleteExprType because it is allowed to be incomplete:

https://godbolt.org/z/5s6s7hn7e

@efriedma-quic
Copy link
Collaborator

I'm not sure we want to scatter checks across the code for specific expressions. See #133963. Maybe we should just immediately fix the type when the declaration is referenced?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

4 participants