[PATCH] D78982: [clang-format] Fix Microsoft style for enums

Aaron Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 21:01:25 PDT 2020


asmith created this revision.
asmith added reviewers: jbcoe, MyDeveloperDay.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
asmith added a reviewer: thakis.

Before this change enums were formatted incorrectly for the Microsoft style.

      

[Original Source]

  
  enum {
    one,
    two
  } three, four;


[Incorrectly Formatted]

  
  enum blah
  {
    one,
    two
  } three,
      four;


[Correct Format with Patch]

  
  enum blah
  {
    one,
    two
  } three, four;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78982

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2280,9 +2280,18 @@
     return true;
   }
 
+  if (Style.BraceWrapping.AfterEnum)
+    addUnwrappedLine();
   // Parse enum body.
   nextToken();
+  if (Style.BraceWrapping.AfterEnum) {
+    addUnwrappedLine();
+    Line->Level += 1;
+  }
   bool HasError = !parseBracedList(/*ContinueOnSemicolons=*/true);
+  if (Style.BraceWrapping.AfterEnum)
+    Line->Level -= 1;
+  
   if (HasError) {
     if (FormatTok->is(tok::semi))
       nextToken();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78982.260540.patch
Type: text/x-patch
Size: 656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200428/e51c5a7b/attachment.bin>


More information about the cfe-commits mailing list