diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 709e0b856d4b..0034235c32d0 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 62ca9ffcc39d..5395fd98923f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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;");