From: Jacob Bandes-Storch Date: Thu, 10 Aug 2017 01:30:22 +0000 (+0000) Subject: [clang-format] let PointerAlignment dictate spacing of function ref qualifiers X-Git-Tag: llvmorg-6.0.0-rc1~10442 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58933c5d034fef6344730c308db8a69736df1796;p=platform%2Fupstream%2Fllvm.git [clang-format] let PointerAlignment dictate spacing of function ref qualifiers Summary: The original changes for ref qualifiers in rL272537 and rL272548 allowed function const+ref qualifier spacing to diverge from the spacing used for variables. It seems more consistent for `T const& x;` to match `void foo() const&;`. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D34324 llvm-svn: 310544 --- diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 37583cd..31693e1 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2216,8 +2216,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return false; if (Right.is(TT_PointerOrReference)) return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) || - (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous && - Left.Previous->is(tok::r_paren)) || + (Left.Tok.isLiteral() || (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) && (Style.PointerAlignment != FormatStyle::PAS_Left || (Line.IsMultiVariableDeclStmt && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index dcc96b2..0b3ecf5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5283,7 +5283,8 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) { verifyFormat("SomeType MemberFunction(const Deleted &) && {}"); verifyFormat("SomeType MemberFunction(const Deleted &) && final {}"); verifyFormat("SomeType MemberFunction(const Deleted &) && override {}"); - verifyFormat("SomeType MemberFunction(const Deleted &) const &;"); + verifyFormat("void Fn(T const &) const &;"); + verifyFormat("void Fn(T const volatile &&) const volatile &&;"); verifyFormat("template \n" "void F(T) && = delete;", getGoogleStyle()); @@ -5300,7 +5301,8 @@ TEST_F(FormatTest, UnderstandsFunctionRefQualification) { verifyFormat("auto Function(T... t) & -> void {}", AlignLeft); verifyFormat("auto Function(T) & -> void {}", AlignLeft); verifyFormat("auto Function(T) & -> void;", AlignLeft); - verifyFormat("SomeType MemberFunction(const Deleted&) const &;", AlignLeft); + verifyFormat("void Fn(T const&) const&;", AlignLeft); + verifyFormat("void Fn(T const volatile&&) const volatile&&;", AlignLeft); FormatStyle Spaces = getLLVMStyle(); Spaces.SpacesInCStyleCastParentheses = true;