]> granicus.if.org Git - clang/commitdiff
Fix a problem in digraph handling where "[:" might be treated as "<::" and
authorRichard Trieu <rtrieu@google.com>
Tue, 20 Sep 2011 20:03:50 +0000 (20:03 +0000)
committerRichard Trieu <rtrieu@google.com>
Tue, 20 Sep 2011 20:03:50 +0000 (20:03 +0000)
erronously trigger the digraph correction fix-it.  Include a new test to catch
this in the future.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140175 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/Parser/cxx-casting.cpp

index 89953fd3d8cfd1feb38a807d33c5c3a6d5c847a2..baec6fdd7304c24c27226f2762d5f6586e721a14 100644 (file)
@@ -75,7 +75,7 @@ static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken,
 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);
index cb82c8efdad04f3fc3c6e5b85edfbcae4e64879d..42ad12ee94f306f9e04d412313290c91df8ada4d 100644 (file)
@@ -68,7 +68,8 @@ void test2(char x, struct B * b) {
   (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 @@ void test3() {
   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 '['}}
 }