This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] C/C++: add fix-it hints for various missing symbols


On Mon, 2017-07-03 at 23:01 +0000, Joseph Myers wrote:
> Does the changed location fix bug 7356?

The patch as-written doesn't affect that bug, since the patch only
affects sites that use c_parser_require and cp_parser_require with
certain token types, and the diagnostic in PR 7356 is emitted by the C
FE here:

2174		  /* This can appear in many cases looking nothing like a
2175		     function definition, so we don't give a more specific
2176		     error suggesting there was one.  */
2177		  c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2178				  "or %<__attribute__%>");

(the C++ FE handles it, emitting:

pr7356.c:1:1: error: ‘a’ does not name a type
 a//sample
 ^
)

c_parser_error currently uses the location of the next token, and
concats as description of the next token.

I tried hacking up c_parser_error to unconditionally attempt to use the
location immediately after the previous token.  This "fixes" PR 7356,
giving:

pr7356.c:1:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
 a//sample
  ^

This error message might be better to be worded in terms of the
syntactic thing that came before, which would yield:

pr7356.c:1:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
after declaration
 a//sample
  ^

or somesuch.  Doing so would presumably require adding an extra param to 
c_parser_error, e.g. an enum describing the syntactic elements that go before.

Does this sound worth pursuing as a followup?


Thanks
Dave


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]