https://github.com/owenca created https://github.com/llvm/llvm-project/pull/153529
Fixes #153448 >From a2ae89cec74b1151680dfa1270ceca336dc5b8a7 Mon Sep 17 00:00:00 2001 From: Owen Pan <owenpi...@gmail.com> Date: Wed, 13 Aug 2025 20:09:36 -0700 Subject: [PATCH] [clang-format] Allow breaking before bit-field colons Fixes #153448 --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 4801d27b1395a..184bd7ff49e93 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -6269,7 +6269,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, } if (Right.is(tok::colon) && - !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon)) { + !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon, + TT_BitFieldColon)) { return false; } if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 96cc650f52a5d..6fc008f029b48 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4050,6 +4050,10 @@ TEST_F(FormatTest, FormatsBitfields) { " uchar : 8;\n" " uchar other;\n" "};"); + verifyFormat("struct foo {\n" + " uint8_t i_am_a_bit_field_this_long\n" + " : struct_with_constexpr::i_am_a_constexpr_lengthhhhh;\n" + "};"); FormatStyle Style = getLLVMStyle(); Style.BitFieldColonSpacing = FormatStyle::BFCS_None; verifyFormat("struct Bitfields {\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits