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

via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 24 06:30:17 PST 2023


https://github.com/XDeme created https://github.com/llvm/llvm-project/pull/76336

Fixes llvm/llvm-project#76314

>From 24aa5e41505eebb64288e7369a3b4f35ee0214fc Mon Sep 17 00:00:00 2001
From: XDeme <fernando.tagawa.gamail.com at gmail.com>
Date: Sun, 24 Dec 2023 11:27:31 -0300
Subject: [PATCH] [clang-format] Fix bad indentation with attribute and
 templated type

---
 clang/lib/Format/ContinuationIndenter.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp     | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

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) {



More information about the cfe-commits mailing list