Author: Emilia Dreamer Date: 2022-11-17T11:38:21+02:00 New Revision: df6f4b85138f86be73d58ff3f511df5306cc4b4d
URL: https://github.com/llvm/llvm-project/commit/df6f4b85138f86be73d58ff3f511df5306cc4b4d DIFF: https://github.com/llvm/llvm-project/commit/df6f4b85138f86be73d58ff3f511df5306cc4b4d.diff LOG: [clang-format] Defer formatting of operator< to honor paren spacing 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 Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay Differential Revision: https://reviews.llvm.org/D137474 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 75570552146ce..6c4d908f96c8d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3441,7 +3441,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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 && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 628cb82c863b7..9505fa03d3e85 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -15544,6 +15544,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { 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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits