Update as per review comment
Do not handle constructors anymore since there is no ref-qualification for
constructors:
Remove TT_FunctionLParen since it is no longer needed.
Move the handling of '&;' to determineStarAmpUsage as per comment.
Kept restriction to operator overload and function to attach pointer reference
to right parenthesis, rewrite without TT_FunctionLParen.
http://reviews.llvm.org/D7813
Files:
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -766,8 +766,8 @@
break;
}
if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
- Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
- Previous->Previous->isNot(tok::equal))
+ Previous->isOneOf(tok::star, tok::amp, tok::ampamp) &&
+ Previous->Previous && Previous->Previous->isNot(tok::equal))
Previous->Type = TT_PointerOrReference;
}
}
@@ -972,8 +972,7 @@
bool IsSizeOfOrAlignOf =
LeftOfParens && LeftOfParens->isOneOf(tok::kw_sizeof, tok::kw_alignof);
if (ParensAreType && !ParensCouldEndDecl && !IsSizeOfOrAlignOf &&
- ((Contexts.size() > 1 && Contexts[Contexts.size() - 2].IsExpression) ||
- (Tok.Next && Tok.Next->isBinaryOperator())))
+ (Contexts.size() > 1 && Contexts[Contexts.size() - 2].IsExpression))
IsCast = true;
else if (Tok.Next && Tok.Next->isNot(tok::string_literal) &&
(Tok.Next->Tok.isLiteral() ||
@@ -1040,7 +1039,7 @@
if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
return TT_PointerOrReference;
- if (NextToken->isOneOf(tok::kw_operator, tok::comma))
+ if (NextToken->isOneOf(tok::kw_operator, tok::comma, tok::semi))
return TT_PointerOrReference;
if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
@@ -1663,9 +1662,14 @@
if (Left.is(tok::l_square) && Right.is(tok::amp))
return false;
if (Right.is(TT_PointerOrReference))
- return Left.Tok.isLiteral() ||
- (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
- Style.PointerAlignment != FormatStyle::PAS_Left);
+ 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));
if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
(!Left.is(TT_PointerOrReference) ||
Style.PointerAlignment != FormatStyle::PAS_Right))
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5164,17 +5164,42 @@
verifyFormat("using A::operator+;");
- verifyFormat("Deleted &operator=(const Deleted &)& = default;");
- verifyFormat("Deleted &operator=(const Deleted &)&& = delete;");
- verifyGoogleFormat("Deleted& operator=(const Deleted&)& = default;");
- verifyGoogleFormat("Deleted& operator=(const Deleted&)&& = delete;");
-
verifyFormat("string // break\n"
"operator()() & {}");
verifyFormat("string // break\n"
"operator()() && {}");
}
+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 &)&&;");
+
+ verifyGoogleFormat("Deleted& operator=(const Deleted&)& = default;");
+ verifyGoogleFormat("SomeType MemberFunction(const Deleted&)& = delete;");
+ verifyGoogleFormat("Deleted& operator=(const Deleted&)&;");
+ verifyGoogleFormat("SomeType MemberFunction(const Deleted&)&;");
+
+ 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);
+
+ 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);
+}
+
TEST_F(FormatTest, UnderstandsNewAndDelete) {
verifyFormat("void f() {\n"
" A *a = new A;\n"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits