aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-05-13 16:40:10 -0400
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-17 13:03:17 -0300
commitf7ddd68ce057008b9ddbf973d1b51c94c74110b3 (patch)
tree5d9fe12d862c1956d3a37c670c4a4bc0d1b68641
parent996dc0ea9b70b2b5803c5b35caeb975888e51e76 (diff)
downloadgcc-f7ddd68ce057008b9ddbf973d1b51c94c74110b3.zip
gcc-f7ddd68ce057008b9ddbf973d1b51c94c74110b3.tar.gz
gcc-f7ddd68ce057008b9ddbf973d1b51c94c74110b3.tar.bz2
c++: premature requires-expression folding [PR95020]
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.c (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++/cpp2a/concepts-lambda7.C: New test.
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/constraint.cc4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C14
4 files changed, 27 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 145a5d5..73a6500 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2020-05-13 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/95020
+ * constraint.c (tsubst_requires_expr): Produce a new
+ requires-expression when processing_template_decl, even if
+ template arguments are not dependent.
+
2020-05-13 Marek Polacek <polacek@redhat.com>
PR c++/95066
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 3a17005..eb72bfe 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -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/ChangeLog b/gcc/testsuite/ChangeLog
index e2dea4d..b88e182 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-13 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/95020
+ * g++/cpp2a/concepts-lambda7.C: New test.
+
2020-05-13 Marek Polacek <polacek@redhat.com>
PR c++/95066
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C
new file mode 100644
index 0000000..50746b7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda7.C
@@ -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>();
+}