r272548 - clang-format: Restrict r272537 to function ref qualifiers.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 07:45:12 PDT 2016


Author: djasper
Date: Mon Jun 13 09:45:12 2016
New Revision: 272548

URL: http://llvm.org/viewvc/llvm-project?rev=272548&view=rev
Log:
clang-format: Restrict r272537 to function ref qualifiers.

Seems this isn't generally desirable.

Before:
  int const * a;

After:
  int const* a;

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=272548&r1=272547&r2=272548&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 13 09:45:12 2016
@@ -1994,7 +1994,8 @@ 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.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)));

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=272548&r1=272547&r2=272548&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 13 09:45:12 2016
@@ -5755,6 +5755,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
       "    aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 
+  verifyGoogleFormat("int const* a = &b;");
   verifyGoogleFormat("**outparam = 1;");
   verifyGoogleFormat("*outparam = a * b;");
   verifyGoogleFormat("int main(int argc, char** argv) {}");




More information about the cfe-commits mailing list