Skip to content

Commit 80a3a5f

Browse files
Erich Keanetstellar
authored andcommitted
GH60642: Fix ICE when checking a lambda defined in a concept definition
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. (cherry picked from commit 4bf6cc6)
1 parent 3c27086 commit 80a3a5f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,7 +4569,7 @@ bool TreeTransform<Derived>::TransformTemplateArgument(
45694569
getSema(),
45704570
Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
45714571
: Sema::ExpressionEvaluationContext::ConstantEvaluated,
4572-
/*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4572+
Sema::ReuseLambdaContextDecl, /*ExprContext=*/
45734573
Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
45744574

45754575
Expr *InputExpr = Input.getSourceExpression();

clang/test/SemaTemplate/concepts-lambda.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %clang_cc1 -std=c++20 -verify %s
22
// RUN: %clang_cc1 -std=c++20 -verify %s -triple powerpc64-ibm-aix
3-
// expected-no-diagnostics
43

54
namespace GH57945 {
65
template<typename T>
@@ -92,3 +91,28 @@ struct Foo {
9291
static_assert(ConstructibleWithN<Foo>);
9392

9493
}
94+
95+
// GH60642 reported an assert being hit, make sure we don't assert.
96+
namespace GH60642 {
97+
template<auto Q> concept C = requires { Q.template operator()<float>(); };
98+
template<class> concept D = true;
99+
static_assert(C<[]<D>{}>); // ok
100+
template<class> concept E = C<[]<D>{}>;
101+
static_assert(E<int>); // previously Asserted.
102+
103+
// ensure we properly diagnose when "D" is false.
104+
namespace DIsFalse {
105+
template<auto Q> concept C = requires { Q.template operator()<float>(); };
106+
template<class> concept D = false;
107+
static_assert(C<[]<D>{}>);
108+
// expected-error@-1{{static assertion failed}}
109+
// expected-note@-2{{does not satisfy 'C'}}
110+
// expected-note@-5{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}}
111+
template<class> concept E = C<[]<D>{}>;
112+
static_assert(E<int>);
113+
// expected-error@-1{{static assertion failed}}
114+
// expected-note@-2{{because 'int' does not satisfy 'E'}}
115+
// expected-note@-4{{does not satisfy 'C'}}
116+
// expected-note@-11{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}}
117+
}
118+
}

0 commit comments

Comments
 (0)