aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXDeme <66138117+XDeme@users.noreply.github.com>2023-12-23 04:02:47 -0300
committerGitHub <noreply@github.com>2023-12-22 23:02:47 -0800
commit8097a5d37b70f483d9e441d78aa7f689618fa795 (patch)
tree4bda8f040a8f5d2306fadbe298cd2b2ee8891801
parentf8f8926054dcf47cb0f3166be8d6961afc979290 (diff)
downloadllvm-8097a5d37b70f483d9e441d78aa7f689618fa795.zip
llvm-8097a5d37b70f483d9e441d78aa7f689618fa795.tar.gz
llvm-8097a5d37b70f483d9e441d78aa7f689618fa795.tar.bz2
[clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (#74943)
Fixes llvm/llvm-project#74901
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp20
-rw-r--r--clang/unittests/Format/FormatTest.cpp13
2 files changed, 22 insertions, 11 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index bd319f2..8489a30 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 9772c3b..762fc82 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) {