diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 5d45741c67145..e12642610252a 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -1793,10 +1793,11 @@ bool Parser::ParseReservedName(std::string* name, int col = input_->current().column; DO(ConsumeString(name, error_message)); if (!io::Tokenizer::IsIdentifier(*name)) { - RecordWarning( + RecordError( line, col, absl::StrFormat("Reserved name \"%s\" is not a valid identifier.", *name)); + return false; } return true; } diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 3c16aad4c8e76..888d65dfb7548 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -1745,7 +1745,7 @@ TEST_F(ParseErrorTest, EnumReservedMissingQuotes) { } TEST_F(ParseErrorTest, EnumReservedInvalidIdentifier) { - ExpectHasWarnings( + ExpectHasErrors( R"pb( enum TestEnum { FOO = 1; @@ -1783,7 +1783,7 @@ TEST_F(ParseErrorTest, ReservedMissingQuotes) { } TEST_F(ParseErrorTest, ReservedInvalidIdentifier) { - ExpectHasWarnings( + ExpectHasErrors( R"pb( message Foo { reserved "foo bar";