]> granicus.if.org Git - clang/commitdiff
clang-format: Don't merge const and &, e.g. in function ref qualifiers.
authorDaniel Jasper <djasper@google.com>
Mon, 13 Jun 2016 07:49:28 +0000 (07:49 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 Jun 2016 07:49:28 +0000 (07:49 +0000)
Before (when aligning & to the right):
  SomeType MemberFunction(const Deleted &) const&;

After:
  SomeType MemberFunction(const Deleted &) const &;

This also applies to variable declarations, e.g.:
  int const * a;

However, this form is very uncommon (most people would write
"const int* a" instead) and contracting to "const*" might actually send
the wrong signal of what the const binds to.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272537 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 1f1a32a2b2cc90dac3026b8a80cf16c5778d7e12..8a36aca97e5437ce25e5150e4aa924b96edf76c9 100644 (file)
@@ -1993,7 +1993,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.Tok.isLiteral() || Left.is(tok::kw_const) ||
             (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
              (Style.PointerAlignment != FormatStyle::PAS_Left ||
               Line.IsMultiVariableDeclStmt)));
index 7e3b4ce3571712f3b6e057bdd5ce51f34dc1bbfb..d82770ba683ea8faed8129377475810effbbea95 100644 (file)
@@ -5627,6 +5627,7 @@ 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 &;");
 
   FormatStyle AlignLeft = getLLVMStyle();
   AlignLeft.PointerAlignment = FormatStyle::PAS_Left;
@@ -5640,6 +5641,7 @@ 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);
 
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpacesInCStyleCastParentheses = true;