summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp4
-rw-r--r--clang/unittests/Format/FormatTest.cpp10
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 410a84ecd2c..c4fa784f2a9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index a98e3d55556..45ad5fe39ef 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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<x> d > v; doesn't make sense.
verifyFormat("foo<a < b && c> d > v;");
OpenPOWER on IntegriCloud