[PATCH] Improve diagnostic message for misplaced square brackets

Nico Weber thakis at chromium.org
Sun Feb 23 21:42:19 PST 2014


Oh, nice feature! I didn't look at the patch, but I tried to write this
patch a while ago in http://llvm.org/bugs/show_bug.cgi?id=11739 (which this
patch will fix) and there are a few comments on that bug that might be
interesting (including review comments from zygoloid, test cases, etc). So
if you haven't see that bug, maybe give it a look :-)


On Sun, Feb 23, 2014 at 9:04 PM, Richard Smith <richard at metafoo.co.uk>wrote:

>
>
> ================
> Comment at: lib/Parse/ParseDecl.cpp:4731
> @@ -4715,3 +4730,3 @@
>    if (getLangOpts().CPlusPlus && D.mayHaveIdentifier()) {
>      // ParseDeclaratorInternal might already have parsed the scope.
>      if (D.getCXXScopeSpec().isEmpty()) {
> ----------------
> In this case, I think you probably shouldn't allow square brackets. That
> is, if someone writes:
>
>   int foo::[3]
>
> we shouldn't activate the special case.
>
> ================
> Comment at: lib/Parse/ParseDecl.cpp:4721-4728
> @@ +4720,10 @@
> +  // save some information for a diagnostic later if the identifer is
> found.
> +  if (Tok.is(tok::l_square) && !D.mayOmitIdentifier()) {
> +    UnhandledError = true;
> +    StartLoc = Tok.getLocation();
> +    while (Tok.is(tok::l_square)) {
> +      ParseBracketDeclarator(D);
> +    }
> +    EndLoc = PP.getLocForEndOfToken(D.getLocEnd());
> +  }
> +
> ----------------
> It looks like this will behave strangely if the remaining declarator is
> not just a simple identifier:
>
>   int[3] (*p);
>
> ... will form an 'array of three pointers to int' type, rather than a
> 'pointer to array of three ints' type. Instead, to get this sort of thing
> right, I suggest you consume the array bound, then call ParseDeclarator,
> then add the array bound chunks to the declarator and issue your diagnostic.
>
> To get the diagnostic location right, you could store the location of the
> '[' as the identifier location in the Declarator object or similar.
>
>
> http://llvm-reviews.chandlerc.com/D2712
> _______________________________________________
> 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/20140223/e697ca73/attachment.html>


More information about the cfe-commits mailing list