diff options
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestProto.cpp | 6 |
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 814e8143e17..5c7ab1240c4 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2018,6 +2018,10 @@ bool UnwrappedLineParser::parseEnum() { 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(); diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index f4196f731f6..d5683b5b844 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -107,6 +107,12 @@ TEST_F(FormatTestProto, FormatsEnums) { "};"); } +TEST_F(FormatTestProto, EnumAsFieldName) { + verifyFormat("message SomeMessage {\n" + " required int32 enum = 1;\n" + "}"); +} + TEST_F(FormatTestProto, UnderstandsReturns) { verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);"); } |