protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

[C++] Fail to generate code with reserved keyword

Open xamix opened this issue 1 year ago • 0 comments

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_()

xamix avatar Apr 25 '23 14:04 xamix