[Clang][Sema] Push an evaluation context for type constraints (#93945)

This helps getTemplateInstantiationArgs() to properly recover template
arguments of an enclosing concept Decl.

Fixes https://github.com/llvm/llvm-project/issues/93821
This commit is contained in:
Younan Zhang 2024-06-01 16:16:15 +08:00 committed by GitHub
parent daaaf4e900
commit 16397e8ec7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 1 deletions

View File

@ -822,6 +822,7 @@ Bug Fixes to C++ Support
- Fix a regression introduced in Clang 18 causing incorrect overload resolution in the presence of functions only
differering by their constraints when only one of these function was variadic.
- Fix a crash when a variable is captured by a block nested inside a lambda. (Fixes #GH93625).
- Fixed a type constraint substitution issue involving a generic lambda expression. (#GH93821)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -5660,7 +5660,7 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
LocalInstantiationScope Scope(*this);
EnterExpressionEvaluationContext EECtx{
*this, ExpressionEvaluationContext::ConstantEvaluated, CSD};
*this, ExpressionEvaluationContext::Unevaluated, CSD};
if (!AreArgsDependent &&
CheckConstraintSatisfaction(

View File

@ -5134,6 +5134,20 @@ static bool CheckDeducedPlaceholderConstraints(Sema &S, const AutoType &Type,
return true;
MultiLevelTemplateArgumentList MLTAL(Concept, CanonicalConverted,
/*Final=*/false);
// Build up an EvaluationContext with an ImplicitConceptSpecializationDecl so
// that the template arguments of the constraint can be preserved. For
// example:
//
// template <class T>
// concept C = []<D U = void>() { return true; }();
//
// We need the argument for T while evaluating type constraint D in
// building the CallExpr to the lambda.
EnterExpressionEvaluationContext EECtx(
S, Sema::ExpressionEvaluationContext::Unevaluated,
ImplicitConceptSpecializationDecl::Create(
S.getASTContext(), Concept->getDeclContext(), Concept->getLocation(),
CanonicalConverted));
if (S.CheckConstraintSatisfaction(Concept, {Concept->getConstraintExpr()},
MLTAL, TypeLoc.getLocalSourceRange(),
Satisfaction))

View File

@ -225,3 +225,15 @@ void foo() {
}(x);
}
} // namespace GH73418
namespace GH93821 {
template <class>
concept C = true;
template <class...>
concept D = []<C T = int>() { return true; }();
D auto x = 0;
} // namespace GH93821