Author: paulhoad Date: Fri Oct 4 06:24:15 2019 New Revision: 373746 URL: http://llvm.org/viewvc/llvm-project?rev=373746&view=rev Log: [clang-format] [PR42417] clang-format inserts a space after '->' for operator->() overloading
Summary: https://bugs.llvm.org/show_bug.cgi?id=42417 This revision removes the extra space between the opertor-> and the parens () ``` class Bug { auto operator-> () -> int*; auto operator++(int) -> int; }; ``` Reviewers: klimek, owenpan, byoungyoung, mitchell-stellar Reviewed By: mitchell-stellar Subscribers: cfe-commits Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D68242 Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373746&r1=373745&r2=373746&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Oct 4 06:24:15 2019 @@ -1393,7 +1393,9 @@ private: 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) || Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373746&r1=373745&r2=373746&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Oct 4 06:24:15 2019 @@ -4956,6 +4956,10 @@ TEST_F(FormatTest, DontBreakBeforeQualif 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" "};"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits