[cfe-commits] [PATCH] PR7606: Diagnostic for ',' instead of '; ' at the end of a statement

Richard Smith richard at metafoo.co.uk
Wed Sep 5 16:40:41 PDT 2012


Hi,

This patch needs a few more testcases (both positive and negative). I'd
particularly like tests which cover the places where C++11 allows a braced
initializer list, since you're using '{' as an indicator of
not-an-assignment-expression.

Please make isNotExpressionStart be a static function local to
ParseExpr.cpp, rather than a member of Parser.

Also, instead of replacing the ',' with a ';' and producing a diagnostic,
please just leave the ',' in the token stream and bail out. This will allow
the appropriate point higher up in the parser to produce the relevant
diagnostic (which may not be to replace with a semicolon, depending on the
context). This affects cases like "if (1, {".

You can avoid the EnterToken call by moving the check above the
ConsumeToken call, and checking isNotExpressionStart(NextToken().getKind()).

Thanks!
Richard

On Sat, Sep 1, 2012 at 7:48 AM, Ahmed Bougacha <ahmed.bougacha at gmail.com>wrote:

> Hello, this small patch improves the diagnostic for a typo of ','
> instead of ';' at the end of a statement.
>
> % cat t.c
> int foo() {
>   return 42,
> }
>
> Now yields the following :
>
> % clang -fsyntax-only t.c
> t.c:2:12: error: expected ';' at end of statement
>   return 42,
>            ^
>            ;
> 1 error generated.
>
> Whereas it previously led to :
>
> % clang -fsyntax-only t.c
>
> t.c:3:1: error: expected expression
> }
> ^
> t.c:3:2: error: expected '}'
> }
>  ^
> t.c:1:11: note: to match this '{'
> int foo() {
>           ^
> 2 errors generated.
>
> --
> Amaury de la Vieuville
> Ahmed Bougacha
>
> _______________________________________________
> 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/20120905/8f67d1fd/attachment.html>


More information about the cfe-commits mailing list