From df6f4b85138f86be73d58ff3f511df5306cc4b4d Mon Sep 17 00:00:00 2001 From: Emilia Dreamer Date: Thu, 17 Nov 2022 11:36:05 +0200 Subject: [PATCH] [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 --- clang/lib/Format/TokenAnnotator.cpp | 4 +++- clang/unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7557055..6c4d908 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 628cb82..9505fa03 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" -- 2.7.4