Skip to content

Commit 41ef6fc

Browse files
authored
[clang-format] Fix bad indentation with attribute and templated type (#76336)
Fixes llvm/llvm-project#76314
1 parent ad554d6 commit 41ef6fc

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
398398
}
399399
if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
400400
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
401-
Style.isCpp() &&
401+
State.Line->First->isNot(TT_AttributeSquare) && Style.isCpp() &&
402402
// FIXME: This is a temporary workaround for the case where clang-format
403403
// sets BreakBeforeParameter to avoid bin packing and this creates a
404404
// completely unnecessary line break after a template type that isn't

clang/unittests/Format/FormatTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26295,6 +26295,8 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2629526295
constexpr StringRef Code("[[maybe_unused]] const int i;\n"
2629626296
"[[foo([[]])]] [[maybe_unused]]\n"
2629726297
"int j;\n"
26298+
"[[maybe_unused]]\n"
26299+
"foo<int> k;\n"
2629826300
"[[nodiscard]] inline int f(int &i);\n"
2629926301
"[[foo([[]])]] [[nodiscard]]\n"
2630026302
"int g(int &i);\n"
@@ -26315,6 +26317,7 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2631526317
Style.BreakAfterAttributes = FormatStyle::ABS_Never;
2631626318
verifyFormat("[[maybe_unused]] const int i;\n"
2631726319
"[[foo([[]])]] [[maybe_unused]] int j;\n"
26320+
"[[maybe_unused]] foo<int> k;\n"
2631826321
"[[nodiscard]] inline int f(int &i);\n"
2631926322
"[[foo([[]])]] [[nodiscard]] int g(int &i);\n"
2632026323
"[[nodiscard]] inline int f(int &i) {\n"
@@ -26332,6 +26335,8 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2633226335
"const int i;\n"
2633326336
"[[foo([[]])]] [[maybe_unused]]\n"
2633426337
"int j;\n"
26338+
"[[maybe_unused]]\n"
26339+
"foo<int> k;\n"
2633526340
"[[nodiscard]]\n"
2633626341
"inline int f(int &i);\n"
2633726342
"[[foo([[]])]] [[nodiscard]]\n"

0 commit comments

Comments
 (0)