[clang] [clang-format] Don't align ctors and dtors with other functions (PR #67618)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/67618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't align ctors and dtors with other functions (PR #67618)
https://github.com/rymiel approved this pull request. https://github.com/llvm/llvm-project/pull/67618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't align ctors and dtors with other functions (PR #67618)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/67618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't align ctors and dtors with other functions (PR #67618)
llvmbot wrote: @llvm/pr-subscribers-clang-format Changes Fixed #67604. --- Full diff: https://github.com/llvm/llvm-project/pull/67618.diff 2 Files Affected: - (modified) clang/lib/Format/WhitespaceManager.cpp (+5-1) - (modified) clang/unittests/Format/FormatTest.cpp (+12) ``diff diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 1790a9df42b5d14..762729d1c4166a5 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -974,7 +974,11 @@ void WhitespaceManager::alignConsecutiveDeclarations() { AlignTokens( Style, [](Change const ) { -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 0d0fbdb84e3271b..713d908d130c2db 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -18677,6 +18677,12 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("inta(int x);\n" "double b();", Alignment); + verifyFormat("struct Test {\n" + " Test(const Test &) = default;\n" + " ~Test() = default;\n" + " Test =(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 =(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. `` https://github.com/llvm/llvm-project/pull/67618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Don't align ctors and dtors with other functions (PR #67618)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/67618 Fixed #67604. >From dfa92b41b74e554157467ea51f5db9dfcec4fcce Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Wed, 27 Sep 2023 16:06:48 -0700 Subject: [PATCH] [clang-format] Don't align ctors and dtors with other functions Fixed #67604. --- clang/lib/Format/WhitespaceManager.cpp | 6 +- clang/unittests/Format/FormatTest.cpp | 12 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 1790a9df42b5d14..762729d1c4166a5 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -974,7 +974,11 @@ void WhitespaceManager::alignConsecutiveDeclarations() { AlignTokens( Style, [](Change const ) { -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 0d0fbdb84e3271b..713d908d130c2db 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -18677,6 +18677,12 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("inta(int x);\n" "double b();", Alignment); + verifyFormat("struct Test {\n" + " Test(const Test &) = default;\n" + " ~Test() = default;\n" + " Test =(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 =(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. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits