From 02e25db5431846e0c69e2656d09f91b4db567e43 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Tue, 20 Sep 2011 20:03:50 +0000 Subject: [PATCH] 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. llvm-svn: 140175 --- clang/lib/Parse/ParseExprCXX.cpp | 2 +- clang/test/Parser/cxx-casting.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 89953fd3d8cf..baec6fdd7304 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -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); diff --git a/clang/test/Parser/cxx-casting.cpp b/clang/test/Parser/cxx-casting.cpp index cb82c8efdad0..42ad12ee94f3 100644 --- a/clang/test/Parser/cxx-casting.cpp +++ b/clang/test/Parser/cxx-casting.cpp @@ -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 D {}; + // This note comes from "::D[:F> A5;" +template class D {}; // expected-note{{template is declared here}} template 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 '['}} }