Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1387,7 +1387,9 @@ Style.Language == FormatStyle::LK_Java) { Current.Type = TT_LambdaArrow; } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration && - Current.NestingLevel == 0) { + Current.NestingLevel == 0 && + !Current.Previous->is(tok::kw_operator)) { + // not auto operator->() -> xxx; Current.Type = TT_TrailingReturnArrow; TrailingReturnFound = true; } else if (Current.is(tok::star) || Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -4830,6 +4830,10 @@ TEST_F(FormatTest, TrailingReturnType) { verifyFormat("auto foo() -> int;\n"); + // correct trailing return type spacing + verifyFormat("auto operator->() -> int;\n"); + verifyFormat("auto operator++(int) -> int;\n"); + verifyFormat("struct S {\n" " auto bar() const -> int;\n" "};");