r310544 - [clang-format] let PointerAlignment dictate spacing of function ref qualifiers

Jacob Bandes-Storch via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 18:30:22 PDT 2017


Author: jtbandes
Date: Wed Aug  9 18:30:22 2017
New Revision: 310544

URL: http://llvm.org/viewvc/llvm-project?rev=310544&view=rev
Log:
[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

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=310544&r1=310543&r2=310544&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Aug  9 18:30:22 2017
@@ -2216,8 +2216,7 @@ bool TokenAnnotator::spaceRequiredBetwee
     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 &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=310544&r1=310543&r2=310544&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug  9 18:30:22 2017
@@ -5283,7 +5283,8 @@ TEST_F(FormatTest, UnderstandsFunctionRe
   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 <typename T>\n"
                "void F(T) && = delete;",
                getGoogleStyle());
@@ -5300,7 +5301,8 @@ TEST_F(FormatTest, UnderstandsFunctionRe
   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;




More information about the cfe-commits mailing list