summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-02-25 10:30:06 +0000
committerDaniel Jasper <djasper@google.com>2015-02-25 10:30:06 +0000
commit1c220488346e2f471147b7a42f5c31de49ffdd12 (patch)
tree0c194f4b40fbe4af5ad12b2cffbeeda5c55c15e5 /clang
parentcd94c40b10573ce45604ac013241639d3d4c65b5 (diff)
downloadbcm5719-llvm-1c220488346e2f471147b7a42f5c31de49ffdd12.tar.gz
bcm5719-llvm-1c220488346e2f471147b7a42f5c31de49ffdd12.zip
clang-format: Fix spacing for function with ref-qualification ..
.. when using SpacesInCStyleCastParentheses != SpacesInParentheses. Before: FormatStyle Spaces = getLLVMStyle(); Deleted &operator=(const Deleted &)& = default; Spaces.SpacesInParentheses = true; Deleted(const Deleted &)& = default; Spaces.SpacesInCStyleCastParentheses = true; Spaces.SpacesInParentheses= false; Deleted( const Deleted & )& = default; After: FormatStyle Spaces = getLLVMStyle(); Deleted &operator=(const Deleted &)& = default;; Spaces.SpacesInParentheses= true; Deleted( const Deleted & )& = default; Spaces.SpacesInCStyleCastParentheses = true; Spaces.SpacesInParentheses= false; Deleted(const Deleted &)& = default; Patch by Jean-Philippe Dufraigne. Thank you! llvm-svn: 230473
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp20
-rw-r--r--clang/unittests/Format/FormatTest.cpp35
2 files changed, 42 insertions, 13 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 568fb2642c9..83e19c55e43 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -766,8 +766,8 @@ private:
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 @@ private:
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 @@ private:
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 @@ 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.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))
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 999b8f3acd3..3e14d1481ed 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5164,17 +5164,42 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
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"
OpenPOWER on IntegriCloud