[cfe-commits] r140175 - in /cfe/trunk: lib/Parse/ParseExprCXX.cpp test/Parser/cxx-casting.cpp

Richard Trieu rtrieu at google.com
Tue Sep 20 13:03:50 PDT 2011


Author: rtrieu
Date: Tue Sep 20 15:03:50 2011
New Revision: 140175

URL: http://llvm.org/viewvc/llvm-project?rev=140175&view=rev
Log:
Fix a problem in digraph handling where "[:" might be treated as "<::" and
erronously trigger the digraph correction fix-it.  Include a new test to catch
this in the future.

Modified:
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/test/Parser/cxx-casting.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=140175&r1=140174&r2=140175&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Tue Sep 20 15:03:50 2011
@@ -75,7 +75,7 @@
 void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType,
                                         bool EnteringContext,
                                         IdentifierInfo &II, CXXScopeSpec &SS) {
-  if (!Next.is(tok::l_square) || !Next.getLength() == 2)
+  if (!Next.is(tok::l_square) || Next.getLength() != 2)
     return;
 
   Token SecondToken = GetLookAheadToken(2);

Modified: cfe/trunk/test/Parser/cxx-casting.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-casting.cpp?rev=140175&r1=140174&r2=140175&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-casting.cpp (original)
+++ cfe/trunk/test/Parser/cxx-casting.cpp Tue Sep 20 15:03:50 2011
@@ -68,7 +68,8 @@
   (void)static_cast LCC c>(&x); // expected-error{{found '<::' after a static_cast which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?}}
 }
 
-template <class T> class D {};
+                               // This note comes from "::D[:F> A5;"
+template <class T> class D {}; // expected-note{{template is declared here}}
 template <class T> void E() {};
 class F {};
 
@@ -82,4 +83,10 @@
   D< ::F> A4;
   ::E< ::F>();
   E< ::F>();
+
+  // Make sure that parser doesn't expand '[:' to '< ::'
+  ::D[:F> A5; // expected-error {{cannot refer to class template 'D' without a template argument list}} \
+              // expected-error {{expected expression}} \
+              // expected-error {{expected ']'}} \
+              // expected-note {{to match this '['}}
 }





More information about the cfe-commits mailing list