From 1814a5400af3771f4a0e4d1bcc6d463676daa03a Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 14 Apr 2014 13:15:29 +0000 Subject: [PATCH] clang-format: Fix regression caused by r206165. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206173 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 4 +++- unittests/Format/FormatTest.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 410a84ecd2..c4fa784f2a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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 && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a98e3d5555..45ad5fe39e 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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 d > v; doesn't make sense. verifyFormat("foo d > v;"); -- 2.40.0