[PATCH] D116188: [clang-format] Fix short enums getting wrapped even when denied
Gabriel Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 23 11:36:34 PST 2021
yodaldevoid updated this revision to Diff 396060.
yodaldevoid added a comment.
Correct commit email
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116188/new/
https://reviews.llvm.org/D116188
Files:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2504,6 +2504,7 @@
FormatStyle Style = getLLVMStyle();
Style.AllowShortEnumsOnASingleLine = true;
verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
+ verifyFormat("typedef enum { A, B, C } ShortEnum1, ShortEnum2;", Style);
Style.AllowShortEnumsOnASingleLine = false;
verifyFormat("enum {\n"
" A,\n"
@@ -2511,6 +2512,20 @@
" C\n"
"} ShortEnum1, ShortEnum2;",
Style);
+ verifyFormat("typedef enum {\n"
+ " A,\n"
+ " B,\n"
+ " C\n"
+ "} ShortEnum1, ShortEnum2;",
+ Style);
+ verifyFormat("enum {\n"
+ " A,\n"
+ "} ShortEnum1, ShortEnum2;",
+ Style);
+ verifyFormat("typedef enum {\n"
+ " A,\n"
+ "} ShortEnum1, ShortEnum2;",
+ Style);
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.AfterEnum = true;
verifyFormat("enum\n"
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -393,11 +393,18 @@
// Try to merge a block with left brace wrapped that wasn't yet covered
if (TheLine->Last->is(tok::l_brace)) {
+ const FormatToken *Tok = TheLine->First;
bool ShouldMerge = false;
- if (TheLine->First->isOneOf(tok::kw_class, tok::kw_struct)) {
+ if (Tok->is(tok::kw_typedef)) {
+ Tok = Tok->getNextNonComment();
+ assert(Tok);
+ }
+ if (Tok->isOneOf(tok::kw_class, tok::kw_struct)) {
ShouldMerge = !Style.BraceWrapping.AfterClass ||
(I[1]->First->is(tok::r_brace) &&
!Style.BraceWrapping.SplitEmptyRecord);
+ } else if (Tok->is(tok::kw_enum)) {
+ ShouldMerge = Style.AllowShortEnumsOnASingleLine;
} else {
ShouldMerge = !Style.BraceWrapping.AfterFunction ||
(I[1]->First->is(tok::r_brace) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116188.396060.patch
Type: text/x-patch
Size: 2304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211223/6e6f415d/attachment-0001.bin>
More information about the cfe-commits
mailing list