jtbandes created this revision. Herald added a subscriber: klimek. Fixes an issue where `struct A { int X; };` would be broken onto multiple lines, but `typedef struct A { int X; } A2;` was collapsed onto a single line.
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,8 +365,11 @@ } 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)) + FormatToken *T = + Line.First->is(tok::kw_typedef) ? Line.First->Next : Line.First; + if (T && + T->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.
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,8 +365,11 @@ } 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)) + FormatToken *T = + Line.First->is(tok::kw_typedef) ? Line.First->Next : Line.First; + if (T && + T->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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits