From: Daniel Jasper Date: Tue, 25 Aug 2015 13:40:51 +0000 (+0000) Subject: clang-format: Add space before member function reference qualifiers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5cffd659331719921117bcf2c5b2e5300e75e54;p=clang clang-format: Add space before member function reference qualifiers. Before: SomeType MemberFunction(const Deleted &)&; After: SomeType MemberFunction(const Deleted &) &; Seems to be much more common. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245934 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ac34df2455..5dad651bd9 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1050,7 +1050,8 @@ private: PreviousNotConst->MatchingParen->Previous->is(tok::kw_decltype)) return true; - return (!IsPPKeyword && PreviousNotConst->is(tok::identifier)) || + return (!IsPPKeyword && + PreviousNotConst->isOneOf(tok::identifier, tok::kw_auto)) || PreviousNotConst->is(TT_PointerOrReference) || PreviousNotConst->isSimpleTypeSpecifier(); } @@ -1842,11 +1843,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Left.is(tok::l_square) && Right.is(tok::amp)) return false; if (Right.is(TT_PointerOrReference)) - return !(Left.is(tok::r_paren) && Left.MatchingParen && - (Left.MatchingParen->is(TT_OverloadedOperatorLParen) || - (Left.MatchingParen->Previous && - Left.MatchingParen->Previous->is( - TT_FunctionDeclarationName)))) && + return (Left.is(tok::r_paren) && Left.MatchingParen && + (Left.MatchingParen->is(TT_OverloadedOperatorLParen) || + (Left.MatchingParen->Previous && + Left.MatchingParen->Previous->is(TT_FunctionDeclarationName)))) || (Left.Tok.isLiteral() || (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) && (Style.PointerAlignment != FormatStyle::PAS_Left || diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 2bcc678cbb..691a446d16 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5320,36 +5320,39 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) { } TEST_F(FormatTest, UnderstandsFunctionRefQualification) { - verifyFormat("Deleted &operator=(const Deleted &)& = default;"); - verifyFormat("Deleted &operator=(const Deleted &)&& = delete;"); - verifyFormat("SomeType MemberFunction(const Deleted &)& = delete;"); - verifyFormat("SomeType MemberFunction(const Deleted &)&& = delete;"); - verifyFormat("Deleted &operator=(const Deleted &)&;"); - 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;"); - verifyGoogleFormat("Deleted& operator=(const Deleted&)&;"); - verifyGoogleFormat("SomeType MemberFunction(const Deleted&)&;"); + verifyFormat("Deleted &operator=(const Deleted &) & = default;"); + verifyFormat("Deleted &operator=(const Deleted &) && = delete;"); + verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;"); + verifyFormat("SomeType MemberFunction(const Deleted &) && = delete;"); + verifyFormat("Deleted &operator=(const Deleted &) &;"); + 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 {}"); + + FormatStyle AlignLeft = getLLVMStyle(); + AlignLeft.PointerAlignment = FormatStyle::PAS_Left; + verifyFormat("Deleted& operator=(const Deleted&) & = default;", AlignLeft); + verifyFormat("SomeType MemberFunction(const Deleted&) & = delete;", + AlignLeft); + verifyFormat("Deleted& operator=(const Deleted&) &;", AlignLeft); + verifyFormat("SomeType MemberFunction(const Deleted&) &;", AlignLeft); FormatStyle Spaces = getLLVMStyle(); Spaces.SpacesInCStyleCastParentheses = true; - verifyFormat("Deleted &operator=(const Deleted &)& = default;", Spaces); - verifyFormat("SomeType MemberFunction(const Deleted &)& = delete;", Spaces); - verifyFormat("Deleted &operator=(const Deleted &)&;", Spaces); - verifyFormat("SomeType MemberFunction(const Deleted &)&;", Spaces); + verifyFormat("Deleted &operator=(const Deleted &) & = default;", Spaces); + verifyFormat("SomeType MemberFunction(const Deleted &) & = delete;", Spaces); + verifyFormat("Deleted &operator=(const Deleted &) &;", Spaces); + verifyFormat("SomeType MemberFunction(const Deleted &) &;", Spaces); Spaces.SpacesInCStyleCastParentheses = false; Spaces.SpacesInParentheses = true; - verifyFormat("Deleted &operator=( const Deleted & )& = default;", Spaces); - verifyFormat("SomeType MemberFunction( const Deleted & )& = delete;", Spaces); - verifyFormat("Deleted &operator=( const Deleted & )&;", Spaces); - verifyFormat("SomeType MemberFunction( const Deleted & )&;", Spaces); + verifyFormat("Deleted &operator=( const Deleted & ) & = default;", Spaces); + verifyFormat("SomeType MemberFunction( const Deleted & ) & = delete;", Spaces); + verifyFormat("Deleted &operator=( const Deleted & ) &;", Spaces); + verifyFormat("SomeType MemberFunction( const Deleted & ) &;", Spaces); } TEST_F(FormatTest, UnderstandsNewAndDelete) { @@ -5588,11 +5591,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) {