[cfe-commits] r91016 - in /cfe/trunk: lib/Parse/ParseStmt.cpp lib/Parse/RAIIObjectsForParser.h test/Parser/cxx-stmt.cpp

Douglas Gregor dgregor at apple.com
Wed Dec 9 17:07:50 PST 2009


On Dec 9, 2009, at 4:38 PM, Chris Lattner wrote:

> Author: lattner
> Date: Wed Dec  9 18:38:54 2009
> New Revision: 91016
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=91016&view=rev
> Log:
> fix PR5740: a colon is sacred when parsing case statement expressions!

Looks good for PR5740, but did you audit the parser for other uses of ':' that might be problematic? Labels, the conditional operator, and bitfields come to mind as potential sources of problems.

	- Doug

> Modified:
>    cfe/trunk/lib/Parse/ParseStmt.cpp
>    cfe/trunk/lib/Parse/RAIIObjectsForParser.h
>    cfe/trunk/test/Parser/cxx-stmt.cpp
> 
> Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=91016&r1=91015&r2=91016&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Dec  9 18:38:54 2009
> @@ -279,6 +279,11 @@
>       ConsumeToken();
>     }
> 
> +    /// We don't want to treat 'case x : y' as a potential typo for 'case x::y'.
> +    /// Disable this form of error recovery while we're parsing the case
> +    /// expression.
> +    ColonProtectionRAIIObject ColonProtection(*this);
> +    
>     OwningExprResult LHS(ParseConstantExpression());
>     if (LHS.isInvalid()) {
>       SkipUntil(tok::colon);
> @@ -298,6 +303,8 @@
>         return StmtError();
>       }
>     }
> +    
> +    ColonProtection.restore();
> 
>     if (Tok.isNot(tok::colon)) {
>       Diag(Tok, diag::err_expected_colon_after) << "'case'";
> 
> Modified: cfe/trunk/lib/Parse/RAIIObjectsForParser.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/RAIIObjectsForParser.h?rev=91016&r1=91015&r2=91016&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Parse/RAIIObjectsForParser.h (original)
> +++ cfe/trunk/lib/Parse/RAIIObjectsForParser.h Wed Dec  9 18:38:54 2009
> @@ -50,9 +50,15 @@
>       P.ColonIsSacred = true;
>     }
> 
> -    ~ColonProtectionRAIIObject() {
> +    /// restore - This can be used to restore the state early, before the dtor
> +    /// is run.
> +    void restore() {
>       P.ColonIsSacred = OldVal;
>     }
> +    
> +    ~ColonProtectionRAIIObject() {
> +      restore();
> +    }
>   };
> 
> } // end namespace clang
> 
> Modified: cfe/trunk/test/Parser/cxx-stmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-stmt.cpp?rev=91016&r1=91015&r2=91016&view=diff
> 
> ==============================================================================
> --- cfe/trunk/test/Parser/cxx-stmt.cpp (original)
> +++ cfe/trunk/test/Parser/cxx-stmt.cpp Wed Dec  9 18:38:54 2009
> @@ -1,6 +1,6 @@
> // RUN: clang-cc -fsyntax-only -verify %s
> 
> -void f()
> +void f1()
> {
>   try {
>     ;
> @@ -10,7 +10,7 @@
>   }
> }
> 
> -void g()
> +void f2()
> {
>   try; // expected-error {{expected '{'}}
> 
> @@ -24,7 +24,7 @@
>   catch {} // expected-error {{expected '('}}
> }
> 
> -void h() try {
> +void f3() try {
> } catch(...) {
> }
> 
> @@ -39,3 +39,16 @@
> 
> A::A(char) : i(0) try {} // expected-error {{expected '{' or ','}}
> A::A(int j) try : i(j) {} catch(...) {}
> +
> +
> +
> +// PR5740
> +struct Type { };
> +
> +enum { Type } Kind;
> +void f4() {
> +  int i = 0;
> +  switch (Kind) {
> +    case Type: i = 7; break;  // no error.
> +  }
> +}
> \ No newline at end of file
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list