summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-08-29 13:32:30 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-08-29 13:32:30 +0000
commit81341d70222cffeff4e7fd4ddee31d80120755b3 (patch)
treec97ebf3acdc7851be4c5000bf514348a23c3de21 /clang
parenteca980396e28c365cea957144d4d9260cb173ded (diff)
downloadbcm5719-llvm-81341d70222cffeff4e7fd4ddee31d80120755b3.tar.gz
bcm5719-llvm-81341d70222cffeff4e7fd4ddee31d80120755b3.zip
[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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp26
2 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 032f39d36e2..8e42e3f068f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -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)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8baba8ee576..a216c803f1f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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"
OpenPOWER on IntegriCloud