From: Daniel Jasper Date: Mon, 10 Nov 2014 16:57:30 +0000 (+0000) Subject: clang-format: Fix pointer formatting. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b03c6434c91542ebc969fa2e57fbd802177d890;p=clang clang-format: Fix pointer formatting. Before: void f(Bar* a = nullptr, Bar * b); After: void f(Bar* a = nullptr, Bar* b); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221609 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 62ec93f323..d3d4bb14fd 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -765,6 +765,7 @@ private: Previous && Previous->isOneOf(tok::star, tok::amp); Previous = Previous->Previous) Previous->Type = TT_PointerOrReference; + Contexts.back().IsExpression = false; } else if (Current.Previous && Current.Previous->Type == TT_CtorInitializerColon) { Contexts.back().IsExpression = true; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9d62fbe14f..3485392d4f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4984,6 +4984,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyGoogleFormat( "const char* const p = reinterpret_cast(q);"); verifyGoogleFormat("void f(int i = 0, SomeType** temps = NULL);"); + verifyGoogleFormat("void f(Bar* a = nullptr, Bar* b);"); + verifyGoogleFormat("template \n" + "void f(int i = 0, SomeType** temps = NULL);"); FormatStyle Left = getLLVMStyle(); Left.PointerAlignment = FormatStyle::PAS_Left;