aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-11-09 10:19:07 -0500
committerMarek Polacek <polacek@redhat.com>2020-11-09 14:39:36 -0500
commit3a5f8d745f8e26d973218b088788f22ad197ca67 (patch)
treeb6db6efcdffa3c475dbc13854f1e5f6a7e586917 /gcc/cp/parser.c
parent6624075e7e996d61143bf5fc106fa2cb61c614f6 (diff)
downloadgcc-3a5f8d745f8e26d973218b088788f22ad197ca67.zip
gcc-3a5f8d745f8e26d973218b088788f22ad197ca67.tar.gz
gcc-3a5f8d745f8e26d973218b088788f22ad197ca67.tar.bz2
c++: Fix -Wvexing-parse ICE with omitted int [PR97762]
For declarations like long f(); decl_specifiers->type will be NULL, but I neglected to handle this case, therefore we ICE. So handle this case by pretending we've seen 'int', which is good enough for -Wvexing-parse's purposes. gcc/cp/ChangeLog: PR c++/97762 * parser.c (warn_about_ambiguous_parse): Handle the case when there is no type in the decl-specifiers. gcc/testsuite/ChangeLog: PR c++/97762 * g++.dg/warn/Wvexing-parse8.C: New test.
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r--gcc/cp/parser.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index bbf157e..b14b4c9 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -20652,13 +20652,24 @@ warn_about_ambiguous_parse (const cp_decl_specifier_seq *decl_specifiers,
if (declarator->parenthesized != UNKNOWN_LOCATION)
return;
- tree type = decl_specifiers->type;
- if (TREE_CODE (type) == TYPE_DECL)
- type = TREE_TYPE (type);
+ tree type;
+ if (decl_specifiers->type)
+ {
+ type = decl_specifiers->type;
+ if (TREE_CODE (type) == TYPE_DECL)
+ type = TREE_TYPE (type);
- /* If the return type is void there is no ambiguity. */
- if (same_type_p (type, void_type_node))
- return;
+ /* If the return type is void there is no ambiguity. */
+ if (same_type_p (type, void_type_node))
+ return;
+ }
+ 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;
+ }
auto_diagnostic_group d;
location_t loc = declarator->u.function.parens_loc;