r189749 - clang-format: Fix segfault in overloaded operator parsing.
Daniel Jasper
djasper at google.com
Mon Sep 2 02:20:40 PDT 2013
Author: djasper
Date: Mon Sep 2 04:20:39 2013
New Revision: 189749
URL: http://llvm.org/viewvc/llvm-project?rev=189749&view=rev
Log:
clang-format: Fix segfault in overloaded operator parsing.
Before, constructs like:
using A::operator+;
caused a segfault. This fixes llvm.org/PR17050.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=189749&r1=189748&r2=189749&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Sep 2 04:20:39 2013
@@ -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) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=189749&r1=189748&r2=189749&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep 2 04:20:39 2013
@@ -3625,6 +3625,8 @@ TEST_F(FormatTest, UnderstandsOverloaded
verifyGoogleFormat("operator void*();");
verifyGoogleFormat("operator SomeType<SomeType<int>>();");
+
+ verifyFormat("using A::operator+;");
}
TEST_F(FormatTest, UnderstandsNewAndDelete) {
More information about the cfe-commits
mailing list