From deadc2760c7086571771c64dfaf58016570be82f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 1 Jul 2015 21:02:24 +0000 Subject: [PATCH] clang-format: Support member function reference qualifiers with trailing return types. Before: template auto x() & -> int {} After: template auto x() & -> int {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241188 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 0117f22200..bbe776fcc7 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1123,7 +1123,7 @@ private: return TT_UnaryOperator; const FormatToken *NextToken = Tok.getNextNonComment(); - if (!NextToken || + if (!NextToken || NextToken->is(tok::arrow) || (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) return TT_Unknown; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ef5299aada..0d85789a1d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5258,11 +5258,6 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) { verifyGoogleFormat("operator ::A();"); verifyFormat("using A::operator+;"); - - verifyFormat("string // break\n" - "operator()() & {}"); - verifyFormat("string // break\n" - "operator()() && {}"); } TEST_F(FormatTest, UnderstandsFunctionRefQualification) { @@ -5526,6 +5521,14 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("A = new SomeType *[Length]();", PointerMiddle); verifyFormat("A = new SomeType *[Length];", PointerMiddle); verifyFormat("T ** t = new T *;", PointerMiddle); + + // Member function reference qualifiers aren't binary operators. + verifyFormat("string // break\n" + "operator()() & {}"); + verifyFormat("string // break\n" + "operator()() && {}"); + verifyGoogleFormat("template \n" + "auto x() & -> int {}"); } TEST_F(FormatTest, UnderstandsAttributes) { -- 2.40.0