[PATCH] D59629: [clang-format] correctly format protobuf fields named "enum".

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 23 07:23:48 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL356833: [clang-format] correctly format protobuf fields named "enum". (authored by paulhoad, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59629/new/

https://reviews.llvm.org/D59629

Files:
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp


Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -2018,6 +2018,10 @@
       FormatTok->isOneOf(tok::colon, tok::question))
     return false;
 
+  // In protobuf, "enum" can be used as a field name.
+  if (Style.Language == FormatStyle::LK_Proto && FormatTok->is(tok::equal))
+    return false;
+
   // Eat up enum class ...
   if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct))
     nextToken();
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -107,6 +107,12 @@
                "};");
 }
 
+TEST_F(FormatTestProto, EnumAsFieldName) {
+  verifyFormat("message SomeMessage {\n"
+               "  required int32 enum = 1;\n"
+               "}");
+}
+
 TEST_F(FormatTestProto, UnderstandsReturns) {
   verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59629.191993.patch
Type: text/x-patch
Size: 1148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190323/33c48c3c/attachment.bin>


More information about the cfe-commits mailing list