From 6598a29b37df5123c0c5a6ad96657053247dfa7c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 1 Nov 2016 06:23:14 +0000 Subject: [PATCH] clang-format: Fix incorrect pointer detection. Before: void f() { f(float{1}, a *a); } After: void f() { f(float{1}, a * a); } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285673 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 5 +++-- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1a3faad6e2..d010efab3e 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -273,8 +273,9 @@ private: !CurrentToken->Next->HasUnescapedNewline && !CurrentToken->Next->isTrailingComment()) HasMultipleParametersOnALine = true; - if (CurrentToken->isOneOf(tok::kw_const, tok::kw_auto) || - CurrentToken->isSimpleTypeSpecifier()) + if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) || + CurrentToken->Previous->isSimpleTypeSpecifier()) && + !CurrentToken->is(tok::l_brace)) Contexts.back().IsExpression = false; if (CurrentToken->isOneOf(tok::semi, tok::colon)) MightBeObjCForRangeLoop = false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 8fe835e579..6ab4a74629 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5870,6 +5870,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("MACRO(auto *a);"); verifyIndependentOfContext("MACRO(const A *a);"); verifyIndependentOfContext("MACRO('0' <= c && c <= '9');"); + verifyFormat("void f() { f(float{1}, a * a); }"); // FIXME: Is there a way to make this work? // verifyIndependentOfContext("MACRO(A *a);"); -- 2.40.0