public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] c++: lambdas inside constraints [PR92652]
@ 2020-06-11 12:57 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-06-11 12:57 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:020d86db8896f088435830595640e6fc21bc64ad
commit 020d86db8896f088435830595640e6fc21bc64ad
Author: Patrick Palka <ppalka@redhat.com>
Date: Fri May 29 09:40:40 2020 -0400
c++: lambdas inside constraints [PR92652]
When parsing a constraint-expression, a requires-clause or a
requires-expression, we temporarily increment processing_template_decl
so that we always obtain template trees which we could later reduce via
substitution even when not inside a template.
But incrementing processing_template_decl when we're already inside a
template has the unintended side effect of shifting up the template
parameter levels of a lambda defined inside one of these constructs,
which leads to confusion later during substitution into the lambda.
This patch fixes this issue by incrementing processing_template_decl
during parsing of these constructs only if it is 0.
Passes 'make check-c++', and also tested by building cmcstl2, does this
look OK to commit after a full bootstrap/regtest?
gcc/cp/ChangeLog:
PR c++/92652
PR c++/93698
PR c++/94128
* parser.c (cp_parser_requires_clause_expression): Temporarily
increment processing_template_decl only if it is 0.
(cp_parser_constraint_expression): Likewise.
(cp_parser_requires_expression): Likewise.
gcc/testsuite/ChangeLog:
PR c++/92652
PR c++/93698
PR c++/94128
* g++.dg/cpp2a/concepts-lambda8.C: New test.
* g++.dg/cpp2a/concepts-lambda9.C: New test.
* g++.dg/cpp2a/concepts-lambda10.C: New test.
Diff:
---
gcc/cp/parser.c | 21 +++++++++++++++------
gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C | 7 +++++++
gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C | 11 +++++++++++
gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C | 11 +++++++++++
4 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 54ca875ce54..74c40efd936 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -27663,11 +27663,16 @@ static tree
cp_parser_requires_clause_expression (cp_parser *parser, bool lambda_p)
{
processing_constraint_expression_sentinel parsing_constraint;
- ++processing_template_decl;
+ temp_override<int> ovr (processing_template_decl);
+ if (!processing_template_decl)
+ /* Adjust processing_template_decl so that we always obtain template
+ trees here. We don't do the usual ++processing_template_decl
+ because that would skew the template parameter depth of a lambda
+ within if we're already inside a template. */
+ processing_template_decl = 1;
cp_expr expr = cp_parser_constraint_logical_or_expression (parser, lambda_p);
if (check_for_bare_parameter_packs (expr))
expr = error_mark_node;
- --processing_template_decl;
return expr;
}
@@ -27684,12 +27689,14 @@ static tree
cp_parser_constraint_expression (cp_parser *parser)
{
processing_constraint_expression_sentinel parsing_constraint;
- ++processing_template_decl;
+ temp_override<int> ovr (processing_template_decl);
+ if (!processing_template_decl)
+ /* As in cp_parser_requires_clause_expression. */
+ processing_template_decl = 1;
cp_expr expr = cp_parser_binary_expression (parser, false, true,
PREC_NOT_OPERATOR, NULL);
if (check_for_bare_parameter_packs (expr))
expr = error_mark_node;
- --processing_template_decl;
expr.maybe_add_location_wrapper ();
return expr;
}
@@ -27798,9 +27805,11 @@ cp_parser_requires_expression (cp_parser *parser)
parms = NULL_TREE;
/* Parse the requirement body. */
- ++processing_template_decl;
+ temp_override<int> ovr (processing_template_decl);
+ if (!processing_template_decl)
+ /* As in cp_parser_requires_clause_expression. */
+ processing_template_decl = 1;
reqs = cp_parser_requirement_body (parser);
- --processing_template_decl;
if (reqs == error_mark_node)
return error_mark_node;
}
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C
new file mode 100644
index 00000000000..392da312b28
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda10.C
@@ -0,0 +1,7 @@
+// PR c++/94128
+// { dg-do compile { target c++20 } }
+
+void test(auto param)
+requires requires{ { [](auto p){return p;}(param) }; };
+
+void test2() { test(1); }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C
new file mode 100644
index 00000000000..c1c9be682d0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda8.C
@@ -0,0 +1,11 @@
+// PR c++/92652
+// { dg-do compile { target concepts } }
+
+template < typename T >
+ requires ([]{return true ;}())
+void h() { }
+
+int main()
+{
+ h<int>();
+}
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C
new file mode 100644
index 00000000000..6b81ba0adac
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda9.C
@@ -0,0 +1,11 @@
+// PR c++/93698
+// { dg-do compile { target concepts } }
+
+#include <utility>
+
+template <int N>
+concept foo = []<std::size_t... Is>(std::index_sequence<Is...>) constexpr {
+ return (Is + ...) > 10;
+}(std::make_index_sequence<N>());
+
+bool a = foo<7>;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-06-11 12:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 12:57 [gcc/devel/c++-modules] c++: lambdas inside constraints [PR92652] Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).