public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-4850] c++: Fix -Wvexing-parse ICE with omitted int [PR97762]
@ 2020-11-09 19:40 Marek Polacek
0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2020-11-09 19:40 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3a5f8d745f8e26d973218b088788f22ad197ca67
commit r11-4850-g3a5f8d745f8e26d973218b088788f22ad197ca67
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Nov 9 10:19:07 2020 -0500
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.
Diff:
---
gcc/cp/parser.c | 23 +++++++++++++++++------
gcc/testsuite/g++.dg/warn/Wvexing-parse8.C | 11 +++++++++++
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index bbf157eb47f..b14b4c90c92 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;
diff --git a/gcc/testsuite/g++.dg/warn/Wvexing-parse8.C b/gcc/testsuite/g++.dg/warn/Wvexing-parse8.C
new file mode 100644
index 00000000000..2d26d22fc4b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wvexing-parse8.C
@@ -0,0 +1,11 @@
+// PR c++/97762
+// { dg-do compile }
+
+void
+g ()
+{
+ long a(); // { dg-warning "empty parentheses" }
+ signed b(); // { dg-warning "empty parentheses" }
+ unsigned c(); // { dg-warning "empty parentheses" }
+ short d(); // { dg-warning "empty parentheses" }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-09 19:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 19:40 [gcc r11-4850] c++: Fix -Wvexing-parse ICE with omitted int [PR97762] Marek Polacek
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).