]> granicus.if.org Git - clang/commitdiff
clang-format: Fix regression caused by r206165.
authorDaniel Jasper <djasper@google.com>
Mon, 14 Apr 2014 13:15:29 +0000 (13:15 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 14 Apr 2014 13:15:29 +0000 (13:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206173 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 410a84ecd2ca9b04a3fc9127f2d49791b4e55e5e..c4fa784f2a992d877ffdd413eb0eb7aca7d4b623 100644 (file)
@@ -111,7 +111,9 @@ private:
       // static_assert, if and while usually contain expressions.
       Contexts.back().IsExpression = true;
     } else if (Line.InPPDirective &&
-               (!Left->Previous || Left->Previous->isNot(tok::identifier))) {
+               (!Left->Previous ||
+                (Left->Previous->isNot(tok::identifier) &&
+                 Left->Previous->Type != TT_OverloadedOperator))) {
       Contexts.back().IsExpression = true;
     } else if (Left->Previous && Left->Previous->is(tok::r_square) &&
                Left->Previous->MatchingParen &&
index a98e3d55556f166e82c1b642e35b730497bbebe0..45ad5fe39ef19d052140b27f4532636e51da93d5 100644 (file)
@@ -4584,6 +4584,16 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");
 
+  EXPECT_EQ("#define OP(x)                                    \\\n"
+            "  ostream &operator<<(ostream &s, const A &a) {  \\\n"
+            "    return s << a.DebugString();                 \\\n"
+            "  }",
+            format("#define OP(x) \\\n"
+                   "  ostream &operator<<(ostream &s, const A &a) { \\\n"
+                   "    return s << a.DebugString(); \\\n"
+                   "  }",
+                   getLLVMStyleWithColumns(50)));
+
   // FIXME: We cannot handle this case yet; we might be able to figure out that
   // foo<x> d > v; doesn't make sense.
   verifyFormat("foo<a < b && c> d > v;");