[PATCH] D144192: GH60642: Fix ICE when checking a lambda defined in a concept definition

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 16 07:54:47 PST 2023


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 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()'}}
+}
+}
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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144192.498023.patch
Type: text/x-patch
Size: 2209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230216/fe6528de/attachment.bin>


More information about the cfe-commits mailing list