#include "TokenAnnotator.h"
#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/Debug.h"
#define DEBUG_TYPE "format-token-annotator"
return false;
break;
case tok::less:
- if ((!Tok->Previous ||
+ if (!NonTemplateLess.count(Tok) &&
+ (!Tok->Previous ||
(!Tok->Previous->Tok.isLiteral() &&
!(Tok->Previous->is(tok::r_paren) && Contexts.size() > 1))) &&
parseAngle()) {
Tok->Type = TT_TemplateOpener;
} else {
Tok->Type = TT_BinaryOperator;
+ NonTemplateLess.insert(Tok);
CurrentToken = Tok;
next();
}
public:
LineType parseLine() {
+ NonTemplateLess.clear();
if (CurrentToken->is(tok::hash))
return parsePreprocessorDirective();
FormatToken *CurrentToken;
bool AutoFound;
const AdditionalKeywords &Keywords;
+
+ // Set of "<" tokens that do not open a template parameter list. If parseAngle
+ // determines that a specific token can't be a template opener, it will make
+ // same decision irrespective of the decisions for tokens leading up to it.
+ // Store this information to prevent this from causing exponential runtime.
+ llvm::SmallPtrSet<FormatToken *, 16> NonTemplateLess;
};
static const int PrecedenceUnaryOperator = prec::PointerToMember + 1;
getLLVMStyleWithColumns(60));
verifyFormat("static_assert(is_convertible<A &&, B>::value, \"AAA\");");
verifyFormat("Constructor(A... a) : a_(X<A>{std::forward<A>(a)}...) {}");
+ verifyFormat("< < < < < < < < < < < < < < < < < < < < < < < < < < < < < <");
}
TEST_F(FormatTest, UnderstandsBinaryOperators) {