aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp6
-rw-r--r--clang/unittests/Format/FormatTest.cpp12
2 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 1790a9d..762729d 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -974,7 +974,11 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
AlignTokens(
Style,
[](Change const &C) {
- if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
+ if (C.Tok->is(TT_FunctionDeclarationName) && C.Tok->Previous &&
+ C.Tok->Previous->isNot(tok::tilde)) {
+ return true;
+ }
+ if (C.Tok->is(TT_FunctionTypeLParen))
return true;
if (C.Tok->isNot(TT_StartOfName))
return false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 6c67c42..0403de8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -18677,6 +18677,12 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
verifyFormat("int a(int x);\n"
"double b();",
Alignment);
+ verifyFormat("struct Test {\n"
+ " Test(const Test &) = default;\n"
+ " ~Test() = default;\n"
+ " Test &operator=(const Test &) = default;\n"
+ "};",
+ Alignment);
unsigned OldColumnLimit = Alignment.ColumnLimit;
// We need to set ColumnLimit to zero, in order to stress nested alignments,
// otherwise the function parameters will be re-flowed onto a single line.
@@ -18713,6 +18719,12 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
"double b();",
Alignment);
Alignment.AlignConsecutiveAssignments.Enabled = true;
+ verifyFormat("struct Test {\n"
+ " Test(const Test &) = default;\n"
+ " ~Test() = default;\n"
+ " Test &operator=(const Test &) = default;\n"
+ "};",
+ Alignment);
// Ensure recursive alignment is broken by function braces, so that the
// "a = 1" does not align with subsequent assignments inside the function
// body.