diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1909,7 +1909,8 @@ } else if (Current.is(tok::arrow) && Style.Language == FormatStyle::LK_Java) { Current.setType(TT_LambdaArrow); - } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration && + } else if (Current.is(tok::arrow) && AutoFound && + (Line.MustBeDeclaration || Line.InPPDirective) && Current.NestingLevel == 0 && !Current.Previous->isOneOf(tok::kw_operator, tok::identifier)) { // not auto operator->() -> xxx; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8010,6 +8010,11 @@ "auto aaaaaaaaaaaaaaaaaaaaaa(T t)\n" " -> decltype(eaaaaaaaaaaaaaaa(t.a).aaaaaaaa());"); + FormatStyle Style = getLLVMStyleWithColumns(60); + verifyFormat("#define MAKE_DEF(NAME) \\\n" + " auto NAME() -> int { return 42; }", + Style); + // Not trailing return types. verifyFormat("void f() { auto a = b->c(); }"); verifyFormat("auto a = p->foo();");