lunasorcery updated this revision to Diff 362220. lunasorcery added a comment.
Sorry it took me so long to get back to this - fell off my radar somewhat. I've updated the release notes, I think it's ready to commit now? I lack commit rights (first time contributor!) so for attribution it'd be "Luna Kirkby <l...@moonbase.lgbt>" CHANGES SINCE LAST ACTION https://reviews.llvm.org/D99840/new/ https://reviews.llvm.org/D99840 Files: clang/docs/ReleaseNotes.rst clang/include/clang/Format/Format.h clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/FormatTestCSharp.cpp Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -402,8 +402,7 @@ } TEST_F(FormatTestCSharp, CSharpKeyWordEscaping) { - verifyFormat("public enum var\n" - "{\n" + verifyFormat("public enum var {\n" " none,\n" " @string,\n" " bool,\n" Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -2451,6 +2451,14 @@ Style.AllowShortEnumsOnASingleLine = true; verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style); Style.AllowShortEnumsOnASingleLine = false; + verifyFormat("enum {\n" + " A,\n" + " B,\n" + " C\n" + "} ShortEnum1, ShortEnum2;", + Style); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterEnum = true; verifyFormat("enum\n" "{\n" " A,\n" @@ -22123,8 +22131,7 @@ Style); // Enumerations are not records and should be unaffected. Style.AllowShortEnumsOnASingleLine = false; - verifyFormat("enum class E\n" - "{\n" + verifyFormat("enum class E {\n" " A,\n" " B\n" "};\n", Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2515,6 +2515,8 @@ if (FormatTok->Tok.is(tok::kw_enum)) nextToken(); + const FormatToken &InitialToken = *FormatTok; + // In TypeScript, "enum" can also be used as property name, e.g. in interface // declarations. An "enum" keyword followed by a colon would be a syntax // error and thus assume it is just an identifier. @@ -2561,7 +2563,8 @@ return true; } - if (!Style.AllowShortEnumsOnASingleLine) + if (!Style.AllowShortEnumsOnASingleLine && + ShouldBreakBeforeBrace(Style, InitialToken)) addUnwrappedLine(); // Parse enum body. nextToken(); Index: clang/include/clang/Format/Format.h =================================================================== --- clang/include/clang/Format/Format.h +++ clang/include/clang/Format/Format.h @@ -544,8 +544,7 @@ /// enum { A, B } myEnum; /// /// false: - /// enum - /// { + /// enum { /// A, /// B /// } myEnum; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -284,6 +284,9 @@ - Support for formatting JSON file (\*.json) has been added to clang-format. +- Option ``AllowShortEnumsOnASingleLine: false`` has been improved, it now + correctly places the opening brace according to ``BraceWrapping.AfterEnum``. + libclang --------
Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -402,8 +402,7 @@ } TEST_F(FormatTestCSharp, CSharpKeyWordEscaping) { - verifyFormat("public enum var\n" - "{\n" + verifyFormat("public enum var {\n" " none,\n" " @string,\n" " bool,\n" Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -2451,6 +2451,14 @@ Style.AllowShortEnumsOnASingleLine = true; verifyFormat("enum { A, B, C } ShortEnum1, ShortEnum2;", Style); Style.AllowShortEnumsOnASingleLine = false; + verifyFormat("enum {\n" + " A,\n" + " B,\n" + " C\n" + "} ShortEnum1, ShortEnum2;", + Style); + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterEnum = true; verifyFormat("enum\n" "{\n" " A,\n" @@ -22123,8 +22131,7 @@ Style); // Enumerations are not records and should be unaffected. Style.AllowShortEnumsOnASingleLine = false; - verifyFormat("enum class E\n" - "{\n" + verifyFormat("enum class E {\n" " A,\n" " B\n" "};\n", Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2515,6 +2515,8 @@ if (FormatTok->Tok.is(tok::kw_enum)) nextToken(); + const FormatToken &InitialToken = *FormatTok; + // In TypeScript, "enum" can also be used as property name, e.g. in interface // declarations. An "enum" keyword followed by a colon would be a syntax // error and thus assume it is just an identifier. @@ -2561,7 +2563,8 @@ return true; } - if (!Style.AllowShortEnumsOnASingleLine) + if (!Style.AllowShortEnumsOnASingleLine && + ShouldBreakBeforeBrace(Style, InitialToken)) addUnwrappedLine(); // Parse enum body. nextToken(); Index: clang/include/clang/Format/Format.h =================================================================== --- clang/include/clang/Format/Format.h +++ clang/include/clang/Format/Format.h @@ -544,8 +544,7 @@ /// enum { A, B } myEnum; /// /// false: - /// enum - /// { + /// enum { /// A, /// B /// } myEnum; Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -284,6 +284,9 @@ - Support for formatting JSON file (\*.json) has been added to clang-format. +- Option ``AllowShortEnumsOnASingleLine: false`` has been improved, it now + correctly places the opening brace according to ``BraceWrapping.AfterEnum``. + libclang --------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits