]> granicus.if.org Git - clang/commitdiff
clang-format: Fix segfault in overloaded operator parsing.
authorDaniel Jasper <djasper@google.com>
Mon, 2 Sep 2013 09:20:39 +0000 (09:20 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 2 Sep 2013 09:20:39 +0000 (09:20 +0000)
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
unittests/Format/FormatTest.cpp

index d2cb5a8723b725233d42bfcb7467fe48a579efe4..5b9802ddd6ed3f8f6c28972a698c6d270a68a031 100644 (file)
@@ -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) {
index 51577a66c7fb9d3ad8dfc6b9e9a68b82dd011f22..bdbc1555e4282c4881a7bdba1c462efa637991e7 100644 (file)
@@ -3625,6 +3625,8 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
 
   verifyGoogleFormat("operator void*();");
   verifyGoogleFormat("operator SomeType<SomeType<int>>();");
+
+  verifyFormat("using A::operator+;");
 }
 
 TEST_F(FormatTest, UnderstandsNewAndDelete) {