[PATCH] D32825: [clang-format] Improve understanding of combined typedef+record declarations
Jacob Bandes-Storch via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 11 01:15:04 PDT 2017
jtbandes updated this revision to Diff 98593.
jtbandes added a comment.
Update from review
https://reviews.llvm.org/D32825
Files:
lib/Format/UnwrappedLineFormatter.cpp
unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -443,6 +443,14 @@
"}",
AllowSimpleBracedStatements);
+ verifyFormat("struct A2 {\n"
+ " int X;\n"
+ "};",
+ AllowSimpleBracedStatements);
+ verifyFormat("typedef struct A2 {\n"
+ " int X;\n"
+ "} A2_t;",
+ AllowSimpleBracedStatements);
verifyFormat("template <int> struct A2 {\n"
" struct B {};\n"
"};",
Index: lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -365,9 +365,14 @@
} else if (Limit != 0 && !Line.startsWith(tok::kw_namespace) &&
!startsExternCBlock(Line)) {
// We don't merge short records.
- if (Line.First->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
- Keywords.kw_interface))
- return 0;
+ {
+ FormatToken *Tok =
+ Line.First->is(tok::kw_typedef) ? Line.First->Next : Line.First;
+ if (Tok &&
+ Tok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
+ Keywords.kw_interface))
+ return 0;
+ }
// Check that we still have three lines and they fit into the limit.
if (I + 2 == E || I[2]->Type == LT_Invalid)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32825.98593.patch
Type: text/x-patch
Size: 1583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170511/a7b63759/attachment.bin>
More information about the cfe-commits
mailing list