Author: Björn Schäpers Date: 2022-07-18T21:41:09+02:00 New Revision: 3c18a8b3a349781eac54144d0cf252bbbce0c4c1
URL: https://github.com/llvm/llvm-project/commit/3c18a8b3a349781eac54144d0cf252bbbce0c4c1 DIFF: https://github.com/llvm/llvm-project/commit/3c18a8b3a349781eac54144d0cf252bbbce0c4c1.diff LOG: [clang-format] Indent TT_CtorInitializerColon after requires clauses Fixes https://github.com/llvm/llvm-project/issues/56215 Differential Revision: https://reviews.llvm.org/D129942 Added: Modified: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 63214f0aa3d5..6c13e09282fc 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1190,6 +1190,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { break; } } + if (NextNonComment->isOneOf(TT_CtorInitializerColon, TT_InheritanceColon, + TT_InheritanceComma)) { + return State.FirstIndent + Style.ConstructorInitializerIndentWidth; + } if ((PreviousNonComment && (PreviousNonComment->ClosesTemplateDeclaration || PreviousNonComment->ClosesRequiresClause || @@ -1264,10 +1268,6 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { Style.BreakInheritanceList == FormatStyle::BILS_AfterColon) { return CurrentState.Indent; } - if (NextNonComment->isOneOf(TT_CtorInitializerColon, TT_InheritanceColon, - TT_InheritanceComma)) { - return State.FirstIndent + Style.ConstructorInitializerIndentWidth; - } if (Previous.is(tok::r_paren) && !Current.isBinaryOperator() && !Current.isOneOf(tok::colon, tok::comment)) { return ContinuationIndent; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6b7454f9afd7..038c29914ef6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -24714,6 +24714,18 @@ TEST_F(FormatTest, RequiresClauses) { "struct S {};", Style); + Style = getLLVMStyle(); + Style.ConstructorInitializerIndentWidth = 4; + Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon; + Style.PackConstructorInitializers = FormatStyle::PCIS_Never; + verifyFormat("constexpr Foo(Foo const &other)\n" + " requires std::is_copy_constructible<T>\n" + " : value{other.value} {\n" + " do_magic();\n" + " do_more_magic();\n" + "}", + Style); + // Not a clause, but we once hit an assert. verifyFormat("#if 0\n" "#else\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits