rymiel created this revision. rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay. Herald added a project: All. rymiel requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
I'm not exactly sure what the intent of that section of `spaceRequiredBetween` is doing, it seems to handle templates and <<, but the part which adds spaces before parens is way later, as part of `spaceRequiredBeforeParens`. Fixes https://github.com/llvm/llvm-project/issues/58821 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137474 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15472,6 +15472,8 @@ Space.SpaceBeforeParens = FormatStyle::SBPO_Always; verifyFormat("int f ();", Space); + verifyFormat("bool operator< ();", Space); + verifyFormat("bool operator> ();", Space); verifyFormat("void f (int a, T b) {\n" " while (true)\n" " continue;\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3426,7 +3426,9 @@ return false; return !Style.Cpp11BracedListStyle; } - return false; + // Don't attempt to format operator<(), as it is handled later. + if (Right.isNot(TT_OverloadedOperatorLParen)) + return false; } if (Right.is(tok::ellipsis)) { return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous &&
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15472,6 +15472,8 @@ Space.SpaceBeforeParens = FormatStyle::SBPO_Always; verifyFormat("int f ();", Space); + verifyFormat("bool operator< ();", Space); + verifyFormat("bool operator> ();", Space); verifyFormat("void f (int a, T b) {\n" " while (true)\n" " continue;\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3426,7 +3426,9 @@ return false; return !Style.Cpp11BracedListStyle; } - return false; + // Don't attempt to format operator<(), as it is handled later. + if (Right.isNot(TT_OverloadedOperatorLParen)) + return false; } if (Right.is(tok::ellipsis)) { return Left.Tok.isLiteral() || (Left.is(tok::identifier) && Left.Previous &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits