forked from OSchip/llvm-project
[clang-format] Fixed typedef enum brace wrapping
Summary: Bug: https://bugs.llvm.org/show_bug.cgi?id=34016 - **Typedef enum part** **Problem:** Clang format does not allow the flag **BraceWrapping.AfterEnum** control the case when our **enum** is preceded by **typedef** keyword (what is common in C language). **Patch description:** Added case to the **"AfterEnum"** flag when our enum does not start a line - is preceded by **typedef** keyword. **After fix:** **CONFIG:** ``` BreakBeforeBraces: Custom BraceWrapping: { AfterClass: true, AfterControlStatement: true, AfterEnum: true, AfterFunction: true, AfterNamespace: false, AfterStruct: true, AfterUnion: true, BeforeCatch: true, BeforeElse: true } ``` **BEFORE:** ``` typedef enum { a, b, c } SomeEnum; ``` **AFTER:** ``` typedef enum { a, b, c } SomeEnum; ``` Contributed by @PriMee! Reviewers: krasimir, djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D37143 llvm-svn: 311998
This commit is contained in:
parent
eca980396e
commit
81341d7022
|
@ -2647,6 +2647,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
|
|||
return Right.HasUnescapedNewline;
|
||||
if (isAllmanBrace(Left) || isAllmanBrace(Right))
|
||||
return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
|
||||
(Line.startsWith(tok::kw_typedef, tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
|
||||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
|
||||
(Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
|
||||
if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)
|
||||
|
|
|
@ -1324,6 +1324,32 @@ TEST_F(FormatTest, FormatsEnumTypes) {
|
|||
verifyFormat("enum X : std::uint32_t { A, B };");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsTypedefEnum) {
|
||||
FormatStyle Style = getLLVMStyle();
|
||||
Style.ColumnLimit = 40;
|
||||
verifyFormat("typedef enum {} EmptyEnum;");
|
||||
verifyFormat("typedef enum { A, B, C } ShortEnum;");
|
||||
verifyFormat("typedef enum {\n"
|
||||
" ZERO = 0,\n"
|
||||
" ONE = 1,\n"
|
||||
" TWO = 2,\n"
|
||||
" THREE = 3\n"
|
||||
"} LongEnum;",
|
||||
Style);
|
||||
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
|
||||
Style.BraceWrapping.AfterEnum = true;
|
||||
verifyFormat("typedef enum {} EmptyEnum;");
|
||||
verifyFormat("typedef enum { A, B, C } ShortEnum;");
|
||||
verifyFormat("typedef enum\n"
|
||||
"{\n"
|
||||
" ZERO = 0,\n"
|
||||
" ONE = 1,\n"
|
||||
" TWO = 2,\n"
|
||||
" THREE = 3\n"
|
||||
"} LongEnum;",
|
||||
Style);
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatsNSEnums) {
|
||||
verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
|
||||
verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
|
||||
|
|
Loading…
Reference in New Issue