Cope with use of the token '>>' inside a template argument list, e.g.,
vector<vector<double>> Matrix;
In C++98/03, this token always means "right shift". However, if we're in
a context where we know that it can't mean "right shift", provide a
friendly reminder to put a space between the two >'s and then treat it
as two >'s as part of recovery.
In C++0x, this token is always broken into two '>' tokens.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65484 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp
index 64fc8fd..65705e8 100644
--- a/lib/Parse/ParseTemplate.cpp
+++ b/lib/Parse/ParseTemplate.cpp
@@ -431,14 +431,24 @@
}
}
- if (Tok.isNot(tok::greater))
+ if (Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater))
return true;
- // Determine the location of the '>'. Only consume this token if the
- // caller asked us to.
+ // Determine the location of the '>' or '>>'. Only consume this
+ // token if the caller asked us to.
RAngleLoc = Tok.getLocation();
- if (ConsumeLastToken)
+ if (Tok.is(tok::greatergreater)) {
+ if (!getLang().CPlusPlus0x)
+ Diag(Tok.getLocation(), diag::err_two_right_angle_brackets_need_space);
+
+ Tok.setKind(tok::greater);
+ if (!ConsumeLastToken) {
+ // Since we're not supposed to consume the '>>' token, we need
+ // to insert a second '>' token after the first.
+ PP.EnterToken(Tok);
+ }
+ } else if (ConsumeLastToken)
ConsumeToken();
return false;
@@ -670,6 +680,6 @@
ConsumeToken();
}
- return Tok.isNot(tok::greater);
+ return Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater);
}