r245934 - clang-format: Add space before member function reference qualifiers.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 25 06:40:52 PDT 2015
Author: djasper
Date: Tue Aug 25 08:40:51 2015
New Revision: 245934
URL: http://llvm.org/viewvc/llvm-project?rev=245934&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=245934&r1=245933&r2=245934&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Aug 25 08:40:51 2015
@@ -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::spaceRequiredBetwee
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 ||
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=245934&r1=245933&r2=245934&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Aug 25 08:40:51 2015
@@ -5320,36 +5320,39 @@ TEST_F(FormatTest, UnderstandsOverloaded
}
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, UnderstandsUsesOfStar
// Member function reference qualifiers aren't binary operators.
verifyFormat("string // break\n"
- "operator()()& {}");
+ "operator()() & {}");
verifyFormat("string // break\n"
- "operator()()&& {}");
+ "operator()() && {}");
verifyGoogleFormat("template <typename T>\n"
- "auto x()& -> int {}");
+ "auto x() & -> int {}");
}
TEST_F(FormatTest, UnderstandsAttributes) {
More information about the cfe-commits
mailing list