From: Daniel Jasper Date: Wed, 7 Oct 2015 01:41:22 +0000 (+0000) Subject: clang-format: Understand array reference types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1718227005d6d5828809904b42911498284426e;p=clang clang-format: Understand array reference types. Before: void f(Type(¶meter)[10]) {} void f(Type (*parameter)[10]) {} After: void f(Type (¶meter)[10]) {} void f(Type (*parameter)[10]) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249502 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 55a1ddd91c..e9a78d8f66 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -155,7 +155,7 @@ private: Left->Type = TT_ObjCMethodExpr; } - bool MightBeFunctionType = CurrentToken->is(tok::star); + bool MightBeFunctionType = CurrentToken->isOneOf(tok::star, tok::amp); bool HasMultipleLines = false; bool HasMultipleParametersOnALine = false; bool MightBeObjCForRangeLoop = diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 581b10baaf..6a265f3dd1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5423,6 +5423,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("return (int **&)a;"); verifyIndependentOfContext("f((*PointerToArray)[10]);"); verifyFormat("void f(Type (*parameter)[10]) {}"); + verifyFormat("void f(Type (¶meter)[10]) {}"); verifyGoogleFormat("return sizeof(int**);"); verifyIndependentOfContext("Type **A = static_cast(P);"); verifyGoogleFormat("Type** A = static_cast(P);");