clang-format: Fix segfault in overloaded operator parsing.
Before, constructs like:
using A::operator+;
caused a segfault. This fixes llvm.org/PR17050.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189749 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index d2cb5a8..5b9802d 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -389,11 +389,12 @@
Tok->Type = TT_BinaryOperator;
break;
case tok::kw_operator:
- while (CurrentToken && CurrentToken->isNot(tok::l_paren)) {
+ while (CurrentToken &&
+ !CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) {
if (CurrentToken->isOneOf(tok::star, tok::amp))
CurrentToken->Type = TT_PointerOrReference;
consumeToken();
- if (CurrentToken->Previous->Type == TT_BinaryOperator)
+ if (CurrentToken && CurrentToken->Previous->Type == TT_BinaryOperator)
CurrentToken->Previous->Type = TT_OverloadedOperator;
}
if (CurrentToken) {