[PATCH] Improve diagnostic message for misplaced square brackets

Richard Smith richard at metafoo.co.uk
Thu May 22 17:12:16 PDT 2014


+static SourceLocation getDiagLoc(Declarator &D, SourceLocation Loc) {

This is a very generic name for quite a specific behavior.
'getMissingDeclaratorIdLoc' or similar?


+    if (Tok.is(tok::l_square)) {

Maybe factor this out into a separate function.
'ParseMisplacedBracketDeclarator' or similar?


+      SavedBracketInfo SavedInfo;
+      SourceLocation Loc = Tok.getLocation();
+
+      while (Tok.is(tok::l_square)) {
+        ParseBracketDeclarator(D, &SavedInfo);

Is it possible to handle this by parsing into a new Declarator here (and
copying its chunks into D once we're done), instead of introducing a
separate SavedBracketInfo code path into ParseBracketDeclarator?


+      // Something went wrong parsing the parens, in which case,
[...]
+      // Adding back the paren info to the end of the Declarator.

Please say "brackets" rather than "parens"; we're pretty consistent about
using "parens" to mean () and not [].


+      SavedInfo->push_back(
+          {DeclaratorChunk::getArray(0, false, false, 0,
T.getOpenLocation(),

MSVC doesn't support this syntax.


On Tue, May 13, 2014 at 3:44 PM, Richard Trieu <rtrieu at google.com> wrote:

> Switching to a recursive solution for misplaced brackets.  Upon seeing a
> bracket before the identifier, parse the brackets and store the info.  Call
> ParseDirectDeclarator again to continue parsing.  After that returns,
> attach the bracket info the Declarator and emit the misplaced bracket error
> with fix-it hint to move the brackets after the identifier.  Additionally,
> store the location of the beginning of the brackets so that other error
> messages may point to a better location.
>
> 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
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140522/1bad7d44/attachment.html>


More information about the cfe-commits mailing list