From: Daniel Jasper Date: Thu, 3 Apr 2014 09:00:49 +0000 (+0000) Subject: clang-format: Understand that "auto" is a type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=faa5d4739d66fd7fabc5acc76fe43e1f9391ca9c;p=clang clang-format: Understand that "auto" is a type. Before: MACRO(auto * a); After: MACRO(auto *a); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205517 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 709e0b856d..0034235c32 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -196,7 +196,7 @@ private: !CurrentToken->Next->HasUnescapedNewline && !CurrentToken->Next->isTrailingComment()) HasMultipleParametersOnALine = true; - if (CurrentToken->is(tok::kw_const) || + if (CurrentToken->isOneOf(tok::kw_const, tok::kw_auto) || CurrentToken->isSimpleTypeSpecifier()) Contexts.back().IsExpression = false; if (!consumeToken()) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 62ca9ffcc3..5395fd9892 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4554,6 +4554,12 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("foo();"); verifyFormat("foo();"); + verifyIndependentOfContext("MACRO(int *i);"); + verifyIndependentOfContext("MACRO(auto *a);"); + verifyIndependentOfContext("MACRO(const A *a);"); + // FIXME: Is there a way to make this work? + // verifyIndependentOfContext("MACRO(A *a);"); + // FIXME: We cannot handle this case yet; we might be able to figure out that // foo d > v; doesn't make sense. verifyFormat("foo d > v;");