Skip to content

[clang-format] Fix operator overload inconsistency in BreakAfterAttributes: Always #74943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 23, 2023

Conversation

XDeme1
Copy link
Contributor

@XDeme1 XDeme1 commented Dec 9, 2023

Fixes #74901

@llvmbot
Copy link
Member

llvmbot commented Dec 9, 2023

@llvm/pr-subscribers-clang-format

Author: None (XDeme)

Changes

Fixes llvm/llvm-project#74901


Full diff: https://github.com/llvm/llvm-project/pull/74943.diff

2 Files Affected:

  • (modified) clang/lib/Format/ContinuationIndenter.cpp (+2-1)
  • (modified) clang/unittests/Format/FormatTest.cpp (+14)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 9e4e939503dfe4..de3768d475e7b2 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -593,7 +593,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
         // name.
         !Style.isJavaScript()) ||
        (Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
-      Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
+      Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter &&
+      (Style.isCpp() && Current.Tok.isNot(tok::kw_operator))) {
     return true;
   }
 
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 24b2fd599dc397..a1f3beed475ff3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26417,6 +26417,20 @@ TEST_F(FormatTest, BreakAfterAttributes) {
                "void g() {}",
                CtorDtorCode, Style);
 
+  Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+  constexpr StringRef OperatorOverloadCode(
+      "struct Foo {\n"
+      "[[maybe_unused]] void operator+();\n"
+      "};\n"
+      "[[nodiscard]] Foo& operator-(Foo&);");
+  verifyFormat("struct Foo {\n"
+               "  [[maybe_unused]]\n"
+               "  void operator+();\n"
+               "};\n"
+               "[[nodiscard]]\n"
+               "Foo& operator-(Foo&);",
+               OperatorOverloadCode, Style);
+
   Style.BreakBeforeBraces = FormatStyle::BS_Linux;
   verifyFormat("struct Foo {\n"
                "  [[deprecated]]\n"

@HazardyKnusperkeks
Copy link
Contributor

I got a mail, but it seems you have deleted the comment? Is it a regression? Could you bisect it?

And you don't need (for me) to comment, when you addressed a comment, just click on resolved. Would reduce the amount of mails in my inbox. ;)

@XDeme1
Copy link
Contributor Author

XDeme1 commented Dec 11, 2023

Is it not a regression, I didn't verify the path of clang-format correctly, I thought I was using clang 16.0.6, but it was using the one I recently built

@owenca owenca merged commit 8097a5d into llvm:main Dec 23, 2023
@XDeme1 XDeme1 deleted the BreakAfterAttributes-OperatorOverload branch December 24, 2023 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-format] BreakAfterAttributes: Always Inconsistency with operator overload
4 participants