[cfe-commits] r141852 - in /cfe/trunk: lib/Parse/ParseDeclCXX.cpp test/Parser/cxx-class.cpp

David Blaikie dblaikie at gmail.com
Wed Oct 12 23:08:43 PDT 2011


Author: dblaikie
Date: Thu Oct 13 01:08:43 2011
New Revision: 141852

URL: http://llvm.org/viewvc/llvm-project?rev=141852&view=rev
Log:
Fix crash-on-invalid, improve error recovery, and test coverage for missing colon after access specifiers in C++

Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/Parser/cxx-class.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=141852&r1=141851&r2=141852&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Thu Oct 13 01:08:43 2011
@@ -2135,12 +2135,23 @@
         // Current token is a C++ access specifier.
         CurAS = AS;
         SourceLocation ASLoc = Tok.getLocation();
+        unsigned TokLength = Tok.getLength();
         ConsumeToken();
-        if (Tok.is(tok::colon))
-          Actions.ActOnAccessSpecifier(AS, ASLoc, Tok.getLocation());
-        else
-          Diag(Tok, diag::err_expected_colon);
-        ConsumeToken();
+        SourceLocation EndLoc;
+        if (Tok.is(tok::colon)) {
+          EndLoc = Tok.getLocation();
+          ConsumeToken();
+        } else if (Tok.is(tok::semi)) {
+          EndLoc = Tok.getLocation();
+          ConsumeToken();
+          Diag(EndLoc, diag::err_expected_colon) 
+            << FixItHint::CreateReplacement(EndLoc, ":");
+        } else {
+          EndLoc = ASLoc.getLocWithOffset(TokLength);
+          Diag(EndLoc, diag::err_expected_colon) 
+            << FixItHint::CreateInsertion(EndLoc, ":");
+        }
+        Actions.ActOnAccessSpecifier(AS, ASLoc, EndLoc);
         continue;
       }
 

Modified: cfe/trunk/test/Parser/cxx-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-class.cpp?rev=141852&r1=141851&r2=141852&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-class.cpp (original)
+++ cfe/trunk/test/Parser/cxx-class.cpp Thu Oct 13 01:08:43 2011
@@ -40,3 +40,20 @@
   } y;
 } bug3177;
 
+// check that we don't consume the token after the access specifier 
+// when it's not a colon
+class D {
+public // expected-error{{expected ':'}}
+  int i;
+};
+
+// consume the token after the access specifier if it's a semicolon 
+// that was meant to be a colon
+class E {
+public; // expected-error{{expected ':'}}
+  int i;
+};
+
+// PR11109 must appear at the end of the source file
+class pr11109r3 { // expected-note{{to match this '{'}}
+  public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}





More information about the cfe-commits mailing list