]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: premature requires-expression folding [PR95020]
authorPatrick Palka <ppalka@redhat.com>
Tue, 2 Jun 2020 12:52:21 +0000 (08:52 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 2 Jun 2020 12:52:21 +0000 (08:52 -0400)
In the testcase below we're prematurely folding away the
requires-expression to 'true' after substituting in the function's
template arguments, but before substituting in the lambda's deduced
template arguments.

This patch removes the uses_template_parms check when deciding in
tsubst_requires_expr whether to keep around a new requires-expression.
Regardless of whether the template arguments are dependent, there still
might be more template parameters to later substitute in (as in the
below testcase) and even if not, tsubst_expr doesn't perform full
semantic processing unless !processing_template_decl, so we should still
wait until then to fold away the requires-expression.

gcc/cp/ChangeLog:

PR c++/95020
* constraint.cc (tsubst_requires_expr): Produce a new
requires-expression when processing_template_decl, even if
template arguments are not dependent.

gcc/testsuite/ChangeLog:

PR c++/95020
* g++.dg/cpp2a/concepts-lambda7.C: New test.

(cherry picked from commit 7e52f8b1e03776575b92574252d9b6bbed9f1af4)

gcc/cp/constraint.cc
gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C [new file with mode: 0644]

index 18190c820dd8bdd2ded1ef4242b2c89c6db9cce4..65c047a2f626a8ef6b7a6b86f2512c7dfaa70db7 100644 (file)
@@ -2173,9 +2173,7 @@ tsubst_requires_expr (tree t, tree args,
   if (reqs == error_mark_node)
     return boolean_false_node;
 
-  /* In certain cases, produce a new requires-expression.
-     Otherwise the value of the expression is true.  */
-  if (processing_template_decl && uses_template_parms (args))
+  if (processing_template_decl)
     return finish_requires_expr (cp_expr_location (t), parms, reqs);
 
   return boolean_true_node;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C
new file mode 100644 (file)
index 0000000..50746b7
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/95020
+// { dg-do compile { target c++2a } }
+
+template<typename>
+void foo() {
+  auto t = [](auto v) {
+    static_assert(requires { *v; }); // { dg-error "static assertion failed" }
+  };
+  t(0);
+}
+
+void bar() {
+  foo<void>();
+}