Implement Sebastian's idea for simplifying our handling of the greater-than operator/delimiter. Also, clean up after ourselves following a failed parse of a template-argument-list
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64166 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index a197f2c..64b2f13 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -64,34 +64,18 @@
/// argument list.
bool GreaterThanIsOperator;
- /// \brief RAII object that makes '>' behave like the closing angle
- /// bracket for a template argument list.
- struct MakeGreaterThanTemplateArgumentListTerminator {
+ /// \brief RAII object that makes '>' behave either as an operator
+ /// or as the closing angle bracket for a template argument list.
+ struct GreaterThanIsOperatorScope {
bool &GreaterThanIsOperator;
bool OldGreaterThanIsOperator;
- MakeGreaterThanTemplateArgumentListTerminator(bool >IO)
+ GreaterThanIsOperatorScope(bool >IO, bool Val)
: GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
- GTIO = false;
+ GreaterThanIsOperator = Val;
}
- ~MakeGreaterThanTemplateArgumentListTerminator() {
- GreaterThanIsOperator = OldGreaterThanIsOperator;
- }
- };
-
- /// \brief RAII object that makes '>' behave like an
- /// operator. Occurs, for example, inside parentheses.
- struct MakeGreaterThanAnOperator {
- bool &GreaterThanIsOperator;
- bool OldGreaterThanIsOperator;
-
- MakeGreaterThanAnOperator(bool >IO)
- : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) {
- GTIO = true;
- }
-
- ~MakeGreaterThanAnOperator() {
+ ~GreaterThanIsOperatorScope() {
GreaterThanIsOperator = OldGreaterThanIsOperator;
}
};
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 0f04d13..f7eeef7 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -1112,7 +1112,7 @@
Parser::ParseParenExpression(ParenParseOption &ExprType,
TypeTy *&CastTy, SourceLocation &RParenLoc) {
assert(Tok.is(tok::l_paren) && "Not a paren expr!");
- MakeGreaterThanAnOperator G(GreaterThanIsOperator);
+ GreaterThanIsOperatorScope G(GreaterThanIsOperator, true);
SourceLocation OpenLoc = ConsumeParen();
OwningExprResult Result(Actions, true);
CastTy = 0;
diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp
index f083be5..fa76714 100644
--- a/lib/Parse/ParseTemplate.cpp
+++ b/lib/Parse/ParseTemplate.cpp
@@ -371,13 +371,17 @@
TemplateArgList TemplateArgs;
TemplateArgIsTypeList TemplateArgIsType;
{
- MakeGreaterThanTemplateArgumentListTerminator G(GreaterThanIsOperator);
+ GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
if (Tok.isNot(tok::greater) &&
ParseTemplateArgumentList(TemplateArgs, TemplateArgIsType)) {
// Try to find the closing '>'.
SkipUntil(tok::greater, true, true);
+
+ // Clean up any template arguments that we successfully parsed.
+ ASTTemplateArgsPtr TemplateArgsPtr(Actions, &TemplateArgs[0],
+ &TemplateArgIsType[0],
+ TemplateArgs.size());
- // FIXME: What's our recovery strategy for failed template-argument-lists?
return;
}
}