Skip to content

Commit 0468fa0

Browse files
authored
[clang-format] Don't align ctors and dtors with other functions (llvm#67618)
Fixed llvm#67604.
1 parent e4114f9 commit 0468fa0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,11 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
974974
AlignTokens(
975975
Style,
976976
[](Change const &C) {
977-
if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
977+
if (C.Tok->is(TT_FunctionDeclarationName) && C.Tok->Previous &&
978+
C.Tok->Previous->isNot(tok::tilde)) {
979+
return true;
980+
}
981+
if (C.Tok->is(TT_FunctionTypeLParen))
978982
return true;
979983
if (C.Tok->isNot(TT_StartOfName))
980984
return false;

clang/unittests/Format/FormatTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18677,6 +18677,12 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
1867718677
verifyFormat("int a(int x);\n"
1867818678
"double b();",
1867918679
Alignment);
18680+
verifyFormat("struct Test {\n"
18681+
" Test(const Test &) = default;\n"
18682+
" ~Test() = default;\n"
18683+
" Test &operator=(const Test &) = default;\n"
18684+
"};",
18685+
Alignment);
1868018686
unsigned OldColumnLimit = Alignment.ColumnLimit;
1868118687
// We need to set ColumnLimit to zero, in order to stress nested alignments,
1868218688
// otherwise the function parameters will be re-flowed onto a single line.
@@ -18713,6 +18719,12 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
1871318719
"double b();",
1871418720
Alignment);
1871518721
Alignment.AlignConsecutiveAssignments.Enabled = true;
18722+
verifyFormat("struct Test {\n"
18723+
" Test(const Test &) = default;\n"
18724+
" ~Test() = default;\n"
18725+
" Test &operator=(const Test &) = default;\n"
18726+
"};",
18727+
Alignment);
1871618728
// Ensure recursive alignment is broken by function braces, so that the
1871718729
// "a = 1" does not align with subsequent assignments inside the function
1871818730
// body.

0 commit comments

Comments
 (0)