]> granicus.if.org Git - clang/commitdiff
clang-format: Restrict r272537 to function ref qualifiers.
authorDaniel Jasper <djasper@google.com>
Mon, 13 Jun 2016 14:45:12 +0000 (14:45 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 Jun 2016 14:45:12 +0000 (14:45 +0000)
Seems this isn't generally desirable.

Before:
  int const * a;

After:
  int const* a;

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

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

index 41bf10dd80089060dca2d8d074b01ccecb0853db..d3a973b591b996a37500ab1d3ed77a4ce98a6edc 100644 (file)
@@ -1994,7 +1994,8 @@ 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.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
+                                     Left.Previous->is(tok::r_paren)) ||
             (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
              (Style.PointerAlignment != FormatStyle::PAS_Left ||
               Line.IsMultiVariableDeclStmt)));
index 3b580b5ae244f172895f042ce1c61cc6cacbb4a7..218243380c3d1d0d8de7c2f88996fd189c37d8df 100644 (file)
@@ -5755,6 +5755,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
       "    aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 
+  verifyGoogleFormat("int const* a = &b;");
   verifyGoogleFormat("**outparam = 1;");
   verifyGoogleFormat("*outparam = a * b;");
   verifyGoogleFormat("int main(int argc, char** argv) {}");