[gcc r11-9388] c++: bogus error w/ tentative type parse of concept-id [PR98394]
Patrick Palka
ppalka@gcc.gnu.org
Wed Dec 15 19:55:20 GMT 2021
https://gcc.gnu.org/g:a94867f67e0b48ba53691f1d5f43f5c7d60adecb
commit r11-9388-ga94867f67e0b48ba53691f1d5f43f5c7d60adecb
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue Nov 9 09:09:43 2021 -0500
c++: bogus error w/ tentative type parse of concept-id [PR98394]
Here when tentatively parsing the if condition as a declaration, we try
to treat C<1> as the start of a constrained placeholder type, which we
quickly reject because C doesn't accept a type as its first argument.
But since we're parsing tentatively, we shouldn't emit an error in this
case.
In passing, also fix PR85846 by only overriding 'tentative' to false when
given a concept-name, and not also when given a concept-id that has an empty
argument list.
PR c++/98394
PR c++/85846
gcc/cp/ChangeLog:
* parser.c (cp_parser_placeholder_type_specifier): Declare
static. Don't override tentative to false when tmpl is a
concept-id with empty argument list. Don't emit a "does not
constrain a type" error when tentative.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-pr98394.C: New test.
* g++.dg/cpp2a/concepts-pr85846.C: New test.
(cherry picked from commit a22d910305a5232694ff48ead37a7f53e46b7202)
Diff:
---
gcc/cp/parser.c | 11 +++++++----
gcc/testsuite/g++.dg/cpp2a/concepts-pr85846.C | 12 ++++++++++++
gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C | 14 ++++++++++++++
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 6990a794af8..8aac2d1803c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -19108,7 +19108,7 @@ cp_parser_simple_type_specifier (cp_parser* parser,
Note that the Concepts TS allows the auto or decltype(auto) to be
omitted in a constrained-type-specifier. */
-tree
+static tree
cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc,
tree tmpl, bool tentative)
{
@@ -19124,7 +19124,7 @@ cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc,
args = TREE_OPERAND (tmpl, 1);
tmpl = TREE_OPERAND (tmpl, 0);
}
- if (args == NULL_TREE)
+ else
/* A concept-name with no arguments can't be an expression. */
tentative = false;
@@ -19162,8 +19162,11 @@ cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc,
if (!flag_concepts_ts
|| !processing_template_parmlist)
{
- error_at (loc, "%qE does not constrain a type", DECL_NAME (con));
- inform (DECL_SOURCE_LOCATION (con), "concept defined here");
+ if (!tentative)
+ {
+ error_at (loc, "%qE does not constrain a type", DECL_NAME (con));
+ inform (DECL_SOURCE_LOCATION (con), "concept defined here");
+ }
return error_mark_node;
}
}
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr85846.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr85846.C
new file mode 100644
index 00000000000..7fda002cfee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr85846.C
@@ -0,0 +1,12 @@
+// PR c++/85846
+// { dg-do compile { target c++20 } }
+
+template<int=0>
+concept A = true;
+
+bool i(A<>);
+
+template<class=int>
+concept B = true;
+
+bool j(B<>);
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C
new file mode 100644
index 00000000000..c8407cdf7cd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C
@@ -0,0 +1,14 @@
+// PR c++/98394
+// { dg-do compile { target c++20 } }
+
+template<int...>
+concept C = true;
+
+template<int, int>
+concept D = true;
+
+int main() {
+ if (C<1>); // { dg-bogus "does not constrain a type" }
+ if (D<1>); // { dg-error "wrong number of template arguments" }
+ // { dg-bogus "does not constrain a type" "" { target *-*-* } .-1 }
+}
More information about the Gcc-cvs
mailing list