[clang] 8097a5d - [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (#74943)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 22 23:02:50 PST 2023
Author: XDeme
Date: 2023-12-22T23:02:47-08:00
New Revision: 8097a5d37b70f483d9e441d78aa7f689618fa795
URL: https://github.com/llvm/llvm-project/commit/8097a5d37b70f483d9e441d78aa7f689618fa795
DIFF: https://github.com/llvm/llvm-project/commit/8097a5d37b70f483d9e441d78aa7f689618fa795.diff
LOG: [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (#74943)
Fixes llvm/llvm-project#74901
Added:
Modified:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index bd319f21b05f86..8489a30dd34ab3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -583,17 +583,15 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
}
- // If the return type spans multiple lines, wrap before the function name.
- if (((Current.is(TT_FunctionDeclarationName) &&
- !State.Line->ReturnTypeWrapped &&
- // Don't break before a C# function when no break after return type.
- (!Style.isCSharp() ||
- Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
- // Don't always break between a JavaScript `function` and the function
- // name.
- !Style.isJavaScript()) ||
- (Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
- Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
+ if (Current.is(TT_FunctionDeclarationName) &&
+ !State.Line->ReturnTypeWrapped &&
+ // Don't break before a C# function when no break after return type.
+ (!Style.isCSharp() ||
+ Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
+ // Don't always break between a JavaScript `function` and the function
+ // name.
+ !Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
+ CurrentState.BreakBeforeParameter) {
return true;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 9772c3be71877f..762fc8254bdfc9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26479,6 +26479,19 @@ TEST_F(FormatTest, BreakAfterAttributes) {
"{\n"
"}",
CtorDtorCode, Style);
+
+ verifyFormat("struct Foo {\n"
+ " [[maybe_unused]]\n"
+ " void operator+();\n"
+ "};\n"
+ "[[nodiscard]]\n"
+ "Foo &operator-(Foo &);",
+ Style);
+
+ Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+ verifyFormat("[[nodiscard]]\n"
+ "Foo& operator-(Foo&);",
+ Style);
}
TEST_F(FormatTest, InsertNewlineAtEOF) {
More information about the cfe-commits
mailing list