[clang] 4bf6cc6 - GH60642: Fix ICE when checking a lambda defined in a concept definition
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 17 06:09:56 PST 2023
Author: Erich Keane
Date: 2023-02-17T06:09:52-08:00
New Revision: 4bf6cc63aa77a7fea7e410f7d45899abcde2b58a
URL: https://github.com/llvm/llvm-project/commit/4bf6cc63aa77a7fea7e410f7d45899abcde2b58a
DIFF: https://github.com/llvm/llvm-project/commit/4bf6cc63aa77a7fea7e410f7d45899abcde2b58a.diff
LOG: 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.
Added:
Modified:
clang/lib/Sema/TreeTransform.h
clang/test/SemaTemplate/concepts-lambda.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index cca0383568201..09b4ac814c4d9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4569,7 +4569,7 @@ bool TreeTransform<Derived>::TransformTemplateArgument(
getSema(),
Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
: Sema::ExpressionEvaluationContext::ConstantEvaluated,
- /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
+ Sema::ReuseLambdaContextDecl, /*ExprContext=*/
Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
Expr *InputExpr = Input.getSourceExpression();
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp b/clang/test/SemaTemplate/concepts-lambda.cpp
index eace722dd6616..8a184cbf4e9bc 100644
--- a/clang/test/SemaTemplate/concepts-lambda.cpp
+++ b/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 @@ struct Foo {
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 at -1{{static assertion failed}}
+// expected-note at -2{{does not satisfy 'C'}}
+// expected-note at -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 at -1{{static assertion failed}}
+// expected-note at -2{{because 'int' does not satisfy 'E'}}
+// expected-note at -4{{does not satisfy 'C'}}
+// expected-note at -11{{because 'Q.template operator()<float>()' would be invalid: no matching member function for call to 'operator()'}}
+}
+}
More information about the cfe-commits
mailing list