Author: Owen Pan Date: 2025-02-20T19:06:51-08:00 New Revision: 204dcafec0ecf0db81d420d2de57b02ada6b09ec
URL: https://github.com/llvm/llvm-project/commit/204dcafec0ecf0db81d420d2de57b02ada6b09ec DIFF: https://github.com/llvm/llvm-project/commit/204dcafec0ecf0db81d420d2de57b02ada6b09ec.diff LOG: [clang-format] Fix a bug in BCIS_AfterColon and `ColumnLimit: 0` (#127964) Fixes #127622 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 3e51b4aab1082..d49128c2b40f8 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -473,9 +473,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { (State.Column + State.Line->Last->TotalLength - Previous.TotalLength > getColumnLimit(State) || CurrentState.BreakBeforeParameter) && - (!Current.isTrailingComment() || Current.NewlinesBefore > 0) && - (Style.BreakConstructorInitializers != FormatStyle::BCIS_BeforeColon || - Style.ColumnLimit > 0 || Current.NewlinesBefore > 0)) { + ((!Current.isTrailingComment() && Style.ColumnLimit > 0) || + Current.NewlinesBefore > 0)) { return true; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d6d028436d39c..132264486100d 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8292,31 +8292,40 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) { Style); Style.ColumnLimit = 0; - verifyFormat("SomeClass::Constructor() :\n" - " a(a) {}", - Style); - verifyFormat("SomeClass::Constructor() noexcept :\n" - " a(a) {}", - Style); - verifyFormat("SomeClass::Constructor() :\n" - " a(a), b(b), c(c) {}", - Style); - verifyFormat("SomeClass::Constructor() :\n" - " a(a) {\n" - " foo();\n" - " bar();\n" - "}", + verifyNoChange("SomeClass::Constructor() :\n" + " a(a) {}", + Style); + verifyNoChange("SomeClass::Constructor() noexcept :\n" + " a(a) {}", + Style); + verifyNoChange("SomeClass::Constructor() :\n" + " a(a), b(b), c(c) {}", + Style); + verifyNoChange("SomeClass::Constructor() :\n" + " a(a) {\n" + " foo();\n" + " bar();\n" + "}", + Style); + verifyFormat("struct Foo {\n" + " int x;\n" + " Foo() : x(0) {}\n" + "};", + "struct Foo {\n" + " int x;\n" + " Foo():x(0) {}\n" + "};", Style); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; - verifyFormat("SomeClass::Constructor() :\n" - " a(a), b(b), c(c) {\n" - "}", - Style); - verifyFormat("SomeClass::Constructor() :\n" - " a(a) {\n" - "}", - Style); + verifyNoChange("SomeClass::Constructor() :\n" + " a(a), b(b), c(c) {\n" + "}", + Style); + verifyNoChange("SomeClass::Constructor() :\n" + " a(a) {\n" + "}", + Style); Style.ColumnLimit = 80; Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits