aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-04-16 16:45:15 -0400
committerPatrick Palka <ppalka@redhat.com>2020-04-17 13:58:52 -0400
commit3f5af3f71195b7f1ebe32bd0d695b59904fff778 (patch)
tree8496bacd99f361bf77fcf1a966edf35a0c2663b3 /gcc
parent2298af0800b292f028298c1eaec42fd3033c4b9b (diff)
downloadgcc-3f5af3f71195b7f1ebe32bd0d695b59904fff778.zip
gcc-3f5af3f71195b7f1ebe32bd0d695b59904fff778.tar.gz
gcc-3f5af3f71195b7f1ebe32bd0d695b59904fff778.tar.bz2
c++: Hard error with tentative parse of declaration [PR88754]
In the testcase for this PR, we try to parse the statement A(value<0>()); first tentatively as a declaration (with a parenthesized declarator), and during this tentative parse we end up issuing a hard error from cp_parser_check_template_parameters about its invalidness as a declaration. Rather than issuing a hard error, it seems we should instead simulate an error since we're parsing tentatively. This would then allow cp_parser_statement to recover and successfully parse the statement as an expression-statement instead. gcc/cp/ChangeLog: PR c++/88754 * parser.c (cp_parser_check_template_parameters): Before issuing a hard error, first try simulating an error instead. gcc/testsuite/ChangeLog: PR c++/88754 * g++.dg/parse/ambig10.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/ambig10.C20
4 files changed, 35 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8410ff1..465f290 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-17 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/88754
+ * parser.c (cp_parser_check_template_parameters): Before issuing a hard
+ error, first try simulating an error instead.
+
2020-04-17 Jakub Jelinek <jakub@redhat.com>
PR other/94629
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 7be4a8f..d2f3f85 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -28530,6 +28530,10 @@ cp_parser_check_template_parameters (cp_parser* parser,
if (!template_id_p
&& parser->num_template_parameter_lists == num_templates + 1)
return true;
+
+ if (cp_parser_simulate_error (parser))
+ return false;
+
/* If there are more template classes than parameter lists, we have
something like:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 15f5cb2..b80e7da 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-17 Patrick Palka <ppalka@redhat.com>
+
+ PR c++/88754
+ * g++.dg/parse/ambig10.C: New test.
+
2020-04-17 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/94090
diff --git a/gcc/testsuite/g++.dg/parse/ambig10.C b/gcc/testsuite/g++.dg/parse/ambig10.C
new file mode 100644
index 0000000..42b04b1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/ambig10.C
@@ -0,0 +1,20 @@
+// PR c++/88754
+// { dg-do compile }
+
+struct A
+{
+ A(int);
+ void foo();
+};
+
+template<int N> int value() { return N; }
+
+void bar()
+{
+ A(value<0>()).foo();
+ A(value<0>());
+ (A(value<0>())).foo();
+
+ A value<0>; // { dg-error "invalid declaration" }
+ A value<0>(); // { dg-error "invalid declaration" }
+}