erichkeane created this revision. erichkeane added a reviewer: clang-language-wg. Herald added a project: All. erichkeane requested review of this revision.
As reported in GH60642, we asserted when there was a lambda defined in a template arguments inside of a concept, which caused us to not properly set up the list of instantiation args. This patch ensures that the 'lambda context decl' correctly falls-through the template argument instantiation, so that it is available when instantiating the lambda, and thus, when setting up the lambda instantiation args list. https://reviews.llvm.org/D144192 Files: clang/lib/Sema/TreeTransform.h clang/test/SemaTemplate/concepts-lambda.cpp Index: clang/test/SemaTemplate/concepts-lambda.cpp =================================================================== --- clang/test/SemaTemplate/concepts-lambda.cpp +++ clang/test/SemaTemplate/concepts-lambda.cpp @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -std=c++20 -verify %s // RUN: %clang_cc1 -std=c++20 -verify %s -triple powerpc64-ibm-aix -// expected-no-diagnostics namespace GH57945 { template<typename T> @@ -92,3 +91,28 @@ static_assert(ConstructibleWithN<Foo>); } + +// GH60642 reported an assert being hit, make sure we don't assert. +namespace GH60642 { +template<auto Q> concept C = requires { Q.template operator()<float>(); }; +template<class> concept D = true; +static_assert(C<[]<D>{}>); // ok +template<class> concept E = C<[]<D>{}>; +static_assert(E<int>); // previously Asserted. + +// ensure we properly diagnose when "D" is false. +namespace DIsFalse { +template<auto Q> concept C = requires { Q.template operator()<float>(); }; +template<class> concept D = false; +static_assert(C<[]<D>{}>); +// expected-error@-1{{static assertion failed}} +// expected-note@-2{{does not satisfy 'C'}} +// expected-note@-5{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}} +template<class> concept E = C<[]<D>{}>; +static_assert(E<int>); +// expected-error@-1{{static assertion failed}} +// expected-note@-2{{because 'int' does not satisfy 'E'}} +// expected-note@-4{{does not satisfy 'C'}} +// expected-note@-11{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}} +} +} Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -4569,7 +4569,7 @@ getSema(), Uneval ? Sema::ExpressionEvaluationContext::Unevaluated : Sema::ExpressionEvaluationContext::ConstantEvaluated, - /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ + Sema::ReuseLambdaContextDecl, /*ExprContext=*/ Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); Expr *InputExpr = Input.getSourceExpression();
Index: clang/test/SemaTemplate/concepts-lambda.cpp =================================================================== --- clang/test/SemaTemplate/concepts-lambda.cpp +++ clang/test/SemaTemplate/concepts-lambda.cpp @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -std=c++20 -verify %s // RUN: %clang_cc1 -std=c++20 -verify %s -triple powerpc64-ibm-aix -// expected-no-diagnostics namespace GH57945 { template<typename T> @@ -92,3 +91,28 @@ static_assert(ConstructibleWithN<Foo>); } + +// GH60642 reported an assert being hit, make sure we don't assert. +namespace GH60642 { +template<auto Q> concept C = requires { Q.template operator()<float>(); }; +template<class> concept D = true; +static_assert(C<[]<D>{}>); // ok +template<class> concept E = C<[]<D>{}>; +static_assert(E<int>); // previously Asserted. + +// ensure we properly diagnose when "D" is false. +namespace DIsFalse { +template<auto Q> concept C = requires { Q.template operator()<float>(); }; +template<class> concept D = false; +static_assert(C<[]<D>{}>); +// expected-error@-1{{static assertion failed}} +// expected-note@-2{{does not satisfy 'C'}} +// expected-note@-5{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}} +template<class> concept E = C<[]<D>{}>; +static_assert(E<int>); +// expected-error@-1{{static assertion failed}} +// expected-note@-2{{because 'int' does not satisfy 'E'}} +// expected-note@-4{{does not satisfy 'C'}} +// expected-note@-11{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}} +} +} Index: clang/lib/Sema/TreeTransform.h =================================================================== --- clang/lib/Sema/TreeTransform.h +++ clang/lib/Sema/TreeTransform.h @@ -4569,7 +4569,7 @@ getSema(), Uneval ? Sema::ExpressionEvaluationContext::Unevaluated : Sema::ExpressionEvaluationContext::ConstantEvaluated, - /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ + Sema::ReuseLambdaContextDecl, /*ExprContext=*/ Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); Expr *InputExpr = Input.getSourceExpression();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits