From 174f60f005167984d00682d1d38a2927b9c04684 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 2 Sep 2013 09:20:39 +0000 Subject: [PATCH] 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 --- lib/Format/TokenAnnotator.cpp | 5 +++-- unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index d2cb5a8723..5b9802ddd6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -389,11 +389,12 @@ private: 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) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 51577a66c7..bdbc1555e4 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3625,6 +3625,8 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) { verifyGoogleFormat("operator void*();"); verifyGoogleFormat("operator SomeType>();"); + + verifyFormat("using A::operator+;"); } TEST_F(FormatTest, UnderstandsNewAndDelete) { -- 2.40.0