aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-11-17 13:39:39 -0500
committerMarek Polacek <polacek@redhat.com>2020-11-21 15:48:15 -0500
commit0999f26098598fe0a499c5b79ad23678ccfe583a (patch)
tree0d73ecd35a9fa5570977301ba2b8b3597b7a2275 /gcc
parent1cb50c0a0e1a535ad39da2708829ac78f0f154d8 (diff)
downloadgcc-0999f26098598fe0a499c5b79ad23678ccfe583a.zip
gcc-0999f26098598fe0a499c5b79ad23678ccfe583a.tar.gz
gcc-0999f26098598fe0a499c5b79ad23678ccfe583a.tar.bz2
c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881]
This invalid (?) code broke my assumption that if decl_specifiers->type is null, there must be any type-specifiers. Turn the assert into an if to fix this crash. gcc/cp/ChangeLog: PR c++/97881 * parser.c (warn_about_ambiguous_parse): Only assume "int" if we actually saw any type-specifiers. gcc/testsuite/ChangeLog: PR c++/97881 * g++.dg/warn/Wvexing-parse9.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/parser.c11
-rw-r--r--gcc/testsuite/g++.dg/warn/Wvexing-parse9.C8
2 files changed, 13 insertions, 6 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ea5af70..cea7cb0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -20790,13 +20790,12 @@ warn_about_ambiguous_parse (const cp_decl_specifier_seq *decl_specifiers,
if (same_type_p (type, void_type_node))
return;
}
+ else if (decl_specifiers->any_type_specifiers_p)
+ /* Code like long f(); will have null ->type. If we have any
+ type-specifiers, pretend we've seen int. */
+ type = integer_type_node;
else
- {
- /* Code like long f(); will have null ->type. If we have any
- type-specifiers, pretend we've seen int. */
- gcc_checking_assert (decl_specifiers->any_type_specifiers_p);
- type = integer_type_node;
- }
+ return;
auto_diagnostic_group d;
location_t loc = declarator->u.function.parens_loc;
diff --git a/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
new file mode 100644
index 0000000..92724bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wvexing-parse9.C
@@ -0,0 +1,8 @@
+// PR c++/97881
+// { dg-do compile }
+
+void
+cb ()
+{
+ volatile _Atomic (int) a1; // { dg-error "" }
+}