From: Daniel Jasper Date: Tue, 28 May 2013 15:27:10 +0000 (+0000) Subject: Fix formatting regression regarding pointers to arrays. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3ff4a2fea4aa6e5182b7799ccb4352e56961a212;p=clang Fix formatting regression regarding pointers to arrays. Before: f( (*PointerToArray)[10]); After: f((*PointerToArray)[10]); This fixes llvm.org/PR16163 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182777 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 67726234a9..5a6d2ddef9 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1077,7 +1077,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return Left.FormatTok->Tok.isLiteral() || ((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) && !Style.PointerBindsToType); - if (Right.Type == TT_FunctionTypeLParen && + if (Right.Type == TT_FunctionTypeLParen && Left.isNot(tok::l_paren) && (Left.Type != TT_PointerOrReference || Style.PointerBindsToType)) return true; if (Left.Type == TT_PointerOrReference) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3bdf59ab9e..96f0ed128b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2981,6 +2981,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("return sizeof(int **);"); verifyIndependentOfContext("return sizeof(int ******);"); verifyIndependentOfContext("return (int **&)a;"); + verifyIndependentOfContext("f((*PointerToArray)[10]);"); verifyFormat("void f(Type (*parameter)[10]) {}"); verifyGoogleFormat("return sizeof(int**);"); verifyIndependentOfContext("Type **A = static_cast(P);");