From 9eea8caa35cc9a5170916a71b79de44524f62c7b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 13 May 2015 12:54:30 +0000 Subject: [PATCH] clang-format: Fix incorrect */& classification. Before: void f() { f(new a(), c *d); } After: void f() { f(new a(), c * d); } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237249 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 4 ++++ unittests/Format/FormatTest.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 3e51417d2c..130e2c3b2a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -234,6 +234,10 @@ private: MightBeObjCForRangeLoop = false; if (MightBeObjCForRangeLoop && CurrentToken->is(Keywords.kw_in)) CurrentToken->Type = TT_ObjCForIn; + // When we discover a 'new', we set CanBeExpression to 'false' in order to + // parse the type correctly. Reset that after a comma. + if (CurrentToken->is(tok::comma)) + Contexts.back().CanBeExpression = true; FormatToken *Tok = CurrentToken; if (!consumeToken()) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d6f0c08bf0..c44708fbf6 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5486,6 +5486,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("Constructor() : a(a), area(a, width * height) {}"); verifyGoogleFormat("MACRO Constructor(const int& i) : a(a), b(b) {}"); verifyFormat("void f() { f(a, c * d); }"); + verifyFormat("void f() { f(new a(), c * d); }"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); -- 2.50.1