Skip to content

Commit 497b2eb

Browse files
authored
[clang-format] Change LLVM style to BreakAfterAttributes == ABS_Leave (#70360)
This patch addresses some examples of bad formatting in Clang. The following commit contains only changes suggested by clang-format: 21689b5. I believe it's a net negative on readability, with a couple of particularly bad cases. Highlights: ```diff - [[clang::preferred_type(bool)]] - mutable unsigned CachedLocalOrUnnamed : 1; + [[clang::preferred_type(bool)]] mutable unsigned CachedLocalOrUnnamed : 1; ``` ```diff - [[clang::preferred_type(TypeDependence)]] - unsigned Dependence : llvm::BitWidth<TypeDependence>; + [[clang::preferred_type(TypeDependence)]] unsigned Dependence + : llvm::BitWidth<TypeDependence>; ``` ```diff - [[clang::preferred_type(ExceptionSpecificationType)]] - unsigned ExceptionSpecType : 4; + [[clang::preferred_type( + ExceptionSpecificationType)]] unsigned ExceptionSpecType : 4; ``` Style guides doesn't appear to have an opinion on this matter.
1 parent 39b9395 commit 497b2eb

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ clang-format
820820
------------
821821
- Add ``AllowBreakBeforeNoexceptSpecifier`` option.
822822
- Add ``AllowShortCompoundRequirementOnASingleLine`` option.
823+
- Change ``BreakAfterAttributes`` from ``Never`` to ``Leave`` in LLVM style.
823824

824825
libclang
825826
--------

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
14761476
/*SplitEmptyFunction=*/true,
14771477
/*SplitEmptyRecord=*/true,
14781478
/*SplitEmptyNamespace=*/true};
1479-
LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Never;
1479+
LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
14801480
LLVMStyle.BreakAfterJavaFieldAnnotations = false;
14811481
LLVMStyle.BreakArrays = true;
14821482
LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26179,7 +26179,6 @@ TEST_F(FormatTest, RemoveSemicolon) {
2617926179

2618026180
TEST_F(FormatTest, BreakAfterAttributes) {
2618126181
FormatStyle Style = getLLVMStyle();
26182-
EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Never);
2618326182

2618426183
constexpr StringRef Code("[[nodiscard]] inline int f(int &i);\n"
2618526184
"[[foo([[]])]] [[nodiscard]]\n"
@@ -26194,6 +26193,10 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2619426193
" return 1;\n"
2619526194
"}");
2619626195

26196+
EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Leave);
26197+
verifyNoChange(Code, Style);
26198+
26199+
Style.BreakAfterAttributes = FormatStyle::ABS_Never;
2619726200
verifyFormat("[[nodiscard]] inline int f(int &i);\n"
2619826201
"[[foo([[]])]] [[nodiscard]] int g(int &i);\n"
2619926202
"[[nodiscard]] inline int f(int &i) {\n"
@@ -26206,9 +26209,6 @@ TEST_F(FormatTest, BreakAfterAttributes) {
2620626209
"}",
2620726210
Code, Style);
2620826211

26209-
Style.BreakAfterAttributes = FormatStyle::ABS_Leave;
26210-
verifyNoChange(Code, Style);
26211-
2621226212
Style.BreakAfterAttributes = FormatStyle::ABS_Always;
2621326213
verifyFormat("[[nodiscard]]\n"
2621426214
"inline int f(int &i);\n"

0 commit comments

Comments
 (0)