[PATCH] Improve diagnostic message for misplaced square brackets

Richard Smith richard at metafoo.co.uk
Wed May 28 19:56:07 PDT 2014


On Wed, May 28, 2014 at 4:11 PM, Richard Trieu <rtrieu at google.com> wrote:

> Add code to handle:
>
>   int [] *a;
>
> This is handled by inserting parens in the token stream, then backtracking
> and have ParseDirectDeclarator handle the parens as normal through
> ParseParenDeclarator.


This seems like more trouble than I'd expected (and it's still not
completely right, since its mini-lookahead-parser misses lots of cases,
such as 'int [] &a;'). Is it possible to handle this differently, as
follows:

 * parse the bracket declarators into TempDeclarator, then
 * parse a direct declarator, then
 * scan the declarator you just parsed and check if it needs parens, and
include them in the fix-it if so

http://reviews.llvm.org/D2712
>
> Files:
>   include/clang/Basic/DiagnosticParseKinds.td
>   include/clang/Parse/Parser.h
>   lib/Parse/ParseDecl.cpp
>   test/Parser/brackets.c
>   test/Parser/brackets.cpp
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140528/93af4ec4/attachment.html>


More information about the cfe-commits mailing list