diff options
author | Marek Polacek <polacek@redhat.com> | 2015-09-15 17:19:11 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-09-15 17:19:11 +0000 |
commit | 0e36f5c7c103e2d897fcbc9728fa98768b386f9a (patch) | |
tree | ea4ad4601177b57e46c4c68bebdfb4668db9e541 /gcc/c/c-parser.c | |
parent | c33c18cdc6b29a312464cb16996530b47a333c98 (diff) | |
download | gcc-0e36f5c7c103e2d897fcbc9728fa98768b386f9a.zip gcc-0e36f5c7c103e2d897fcbc9728fa98768b386f9a.tar.gz gcc-0e36f5c7c103e2d897fcbc9728fa98768b386f9a.tar.bz2 |
re PR c/67580 (Improve error message on missing "struct" tag)
PR c/67580
* c-decl.c (tag_exists_p): New function.
* c-parser.c (c_parser_declaration_or_fndef): Give a hint when
struct/union/enum keywords are missing.
* c-tree.h (tag_exists_p): Declare.
* gcc.dg/pr67580.c: New test.
From-SVN: r227803
Diffstat (limited to 'gcc/c/c-parser.c')
-rw-r--r-- | gcc/c/c-parser.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 4d9cbe0..d5de102 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1539,8 +1539,16 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, || c_parser_peek_2nd_token (parser)->type == CPP_MULT) && (!nested || !lookup_name (c_parser_peek_token (parser)->value))) { - error_at (here, "unknown type name %qE", - c_parser_peek_token (parser)->value); + tree name = c_parser_peek_token (parser)->value; + error_at (here, "unknown type name %qE", name); + /* Give a hint to the user. This is not C++ with its implicit + typedef. */ + if (tag_exists_p (RECORD_TYPE, name)) + inform (here, "use %<struct%> keyword to refer to the type"); + else if (tag_exists_p (UNION_TYPE, name)) + inform (here, "use %<union%> keyword to refer to the type"); + else if (tag_exists_p (ENUMERAL_TYPE, name)) + inform (here, "use %<enum%> keyword to refer to the type"); /* Parse declspecs normally to get a correct pointer type, but avoid a further "fails to be a type name" error. Refuse nested functions |