Skip to content
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

[clang-format] Fix bad indentation with attribute and templated type #76336

Merged
merged 2 commits into from
Dec 29, 2023

Conversation

XDeme1
Copy link
Contributor

@XDeme1 XDeme1 commented Dec 24, 2023

Fixes #76314

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 24, 2023

@llvm/pr-subscribers-clang-format

Author: None (XDeme)

Changes

Fixes llvm/llvm-project#76314


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

2 Files Affected:

  • (modified) clang/lib/Format/ContinuationIndenter.cpp (+1-1)
  • (modified) clang/unittests/Format/FormatTest.cpp (+4)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 8489a30dd34ab3..102504182c4505 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -398,7 +398,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   }
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
        (Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
-        Style.isCpp() &&
+        State.Line->First->isNot(TT_AttributeSquare) && Style.isCpp() &&
         // FIXME: This is a temporary workaround for the case where clang-format
         // sets BreakBeforeParameter to avoid bin packing and this creates a
         // completely unnecessary line break after a template type that isn't
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 762fc8254bdfc9..d5265aa230c7d2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26492,6 +26492,10 @@ TEST_F(FormatTest, BreakAfterAttributes) {
   verifyFormat("[[nodiscard]]\n"
                "Foo& operator-(Foo&);",
                Style);
+
+  verifyFormat("[[maybe_unused]]\n"
+               "foo<int> f;",
+               Style);
 }
 
 TEST_F(FormatTest, InsertNewlineAtEOF) {

@XDeme1
Copy link
Contributor Author

XDeme1 commented Dec 28, 2023

Hi, Thanks for reviewing, could you merge this for me? I don't have write access

clang/unittests/Format/FormatTest.cpp Outdated Show resolved Hide resolved
clang/unittests/Format/FormatTest.cpp Outdated Show resolved Hide resolved
@HazardyKnusperkeks
Copy link
Contributor

Hi, Thanks for reviewing, could you merge this for me? I don't have write access

I could. But I'm no fan of submitting just because one person approved without others having the chance to say something. (As has happened here.)

@HazardyKnusperkeks HazardyKnusperkeks merged commit 41ef6fc into llvm:main Dec 29, 2023
3 of 4 checks passed
@XDeme1 XDeme1 deleted the 76314 branch December 30, 2023 03:48
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] Attributes forces any variable with templated type to indent incorrectly
4 participants