llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) <details> <summary>Changes</summary> CWG2369 revealed another case where we were SFINAE'ing out the invalid result of substitution, but the expression now makes into evaluation. We switch to the concept specialization's context before we check it. This ensures that we're able to realize the invalid expression earlier, so we can avoid evaluating invalid expression, which is a hard error. --- Full diff: https://github.com/llvm/llvm-project/pull/143096.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaTemplate.cpp (+2) - (modified) clang/test/SemaTemplate/concepts.cpp (+31) ``````````diff diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 1d8fea1d72008..ccc532e1fd3de 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -4749,6 +4749,8 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS, EnterExpressionEvaluationContext EECtx{ *this, ExpressionEvaluationContext::Unevaluated, CSD}; + ContextRAII CurContext(*this, CSD->getDeclContext(), + /*NewThisContext=*/false); if (!AreArgsDependent && CheckConstraintSatisfaction( NamedConcept, AssociatedConstraint(NamedConcept->getConstraintExpr()), diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index 3e50a8bce24af..abfc14de9bc75 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1200,3 +1200,34 @@ bool test_val_types() { } } + +namespace CWG2369_Regression { + +enum class KindEnum { + Unknown = 0, + Foo = 1, +}; + +template <typename T> +concept KnownKind = T::kind() != KindEnum::Unknown; + +template <KnownKind T> struct KnownType; + +struct Type { + KindEnum kind() const; + + static Type f(Type t); + + template <KnownKind T> static KnownType<T> f(T t); + + static void g() { + Type t; + f(t); + } +}; + +template <KnownKind T> struct KnownType { + static constexpr KindEnum kind() { return KindEnum::Foo; } +}; + +} `````````` </details> https://github.com/llvm/llvm-project/pull/143096 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits