From fa82f43900c8ffd21d3ca221f607a295a234c159 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 24 Aug 2015 14:28:08 +0000 Subject: [PATCH] clang-format: Make formatting of member function reference qualifiers more consistent. Before: SomeType MemberFunction(const Deleted &)&&; SomeType MemberFunction(const Deleted &) && { ... } After: SomeType MemberFunction(const Deleted &)&&; SomeType MemberFunction(const Deleted &)&& { ... } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245843 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 6 ++++-- lib/Format/TokenAnnotator.cpp | 10 +++++++--- unittests/Format/FormatTest.cpp | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index c5db18c8e0..f50558c6ec 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -525,6 +525,8 @@ private: /// properly supported by Clang's lexer. struct AdditionalKeywords { AdditionalKeywords(IdentifierTable &IdentTable) { + kw_final = &IdentTable.get("final"); + kw_override = &IdentTable.get("override"); kw_in = &IdentTable.get("in"); kw_CF_ENUM = &IdentTable.get("CF_ENUM"); kw_CF_OPTIONS = &IdentTable.get("CF_OPTIONS"); @@ -538,7 +540,6 @@ struct AdditionalKeywords { kw_abstract = &IdentTable.get("abstract"); kw_extends = &IdentTable.get("extends"); - kw_final = &IdentTable.get("final"); kw_implements = &IdentTable.get("implements"); kw_instanceof = &IdentTable.get("instanceof"); kw_interface = &IdentTable.get("interface"); @@ -562,6 +563,8 @@ struct AdditionalKeywords { } // Context sensitive keywords. + IdentifierInfo *kw_final; + IdentifierInfo *kw_override; IdentifierInfo *kw_in; IdentifierInfo *kw_CF_ENUM; IdentifierInfo *kw_CF_OPTIONS; @@ -578,7 +581,6 @@ struct AdditionalKeywords { // Java keywords. IdentifierInfo *kw_abstract; IdentifierInfo *kw_extends; - IdentifierInfo *kw_final; IdentifierInfo *kw_implements; IdentifierInfo *kw_instanceof; IdentifierInfo *kw_interface; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 381433484d..50e04310b6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1139,9 +1139,11 @@ private: return TT_UnaryOperator; const FormatToken *NextToken = Tok.getNextNonComment(); - if (!NextToken || NextToken->is(tok::arrow) || + if (!NextToken || + NextToken->isOneOf(tok::arrow, Keywords.kw_final, + Keywords.kw_override) || (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) - return TT_Unknown; + return TT_PointerOrReference; if (PrevToken->is(tok::coloncolon)) return TT_PointerOrReference; @@ -1855,7 +1857,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, !Line.IsMultiVariableDeclStmt))) return true; if (Left.is(TT_PointerOrReference)) - return Right.Tok.isLiteral() || Right.is(TT_BlockComment) || + return Right.Tok.isLiteral() || + Right.isOneOf(TT_BlockComment, Keywords.kw_final, + Keywords.kw_override) || (Right.is(tok::l_brace) && Right.BlockKind == BK_Block) || (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare, tok::l_paren) && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0f4e46436b..3751697392 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5326,6 +5326,9 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) { verifyFormat("Deleted &operator=(const Deleted &)&&;"); verifyFormat("SomeType MemberFunction(const Deleted &)&;"); verifyFormat("SomeType MemberFunction(const Deleted &)&&;"); + verifyFormat("SomeType MemberFunction(const Deleted &)&& {}"); + verifyFormat("SomeType MemberFunction(const Deleted &)&& final {}"); + verifyFormat("SomeType MemberFunction(const Deleted &)&& override {}"); verifyGoogleFormat("Deleted& operator=(const Deleted&)& = default;"); verifyGoogleFormat("SomeType MemberFunction(const Deleted&)& = delete;"); @@ -5583,11 +5586,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { // Member function reference qualifiers aren't binary operators. verifyFormat("string // break\n" - "operator()() & {}"); + "operator()()& {}"); verifyFormat("string // break\n" - "operator()() && {}"); + "operator()()&& {}"); verifyGoogleFormat("template \n" - "auto x() & -> int {}"); + "auto x()& -> int {}"); } TEST_F(FormatTest, UnderstandsAttributes) { -- 2.40.0