protoc-gen-validate
protoc-gen-validate copied to clipboard
[C++] Fail to generate code with reserved keyword
Hi,
The generator fail to generate compilable code when some field use reserved C++ keyword as name. For example if you declare the following proto object:
message Security {
optional bool signed = 1;
optional bool encrypted = 2;
optional string encrypted_format = 3;
}
Then it generate the following code:
bool Validate(const test::Message_Security& m, pgv::ValidationMsg* err) {
(void)m;
(void)err;
if (m.has_signed()) {
// no validation rules for signed
}
if (m.has_encrypted()) {
// no validation rules for encrypted
}
if (m.has_encrypted_format()) {
// no validation rules for encrypted_format
}
return true;
}
But it do not compile because protoc
changed the name of signed
to signed_
and so the m.has_signed()
should be replaced with m.has_signed_()