diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 032f39d36e23ea92772addb55539a25727ca94fe..8e42e3f068f38218ff504ef3bff88c5876044df8 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 8baba8ee5764765c169f6a6c7e8e50bffa84002f..a216c803f1f64f5dce41191514807c076208d393 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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"