When the --grpc-callback-api option is used, flatc generates invalid C++ code that fails to compile.
The grpctest test project fails with the following error:
2>W:\Dev\flatbuffers\tests\monster_test.grpc.fb.h(361,23): error C2039: 'CallbackService': is not a member of 'MyGame::Example::MonsterStorage'
2>(compiling source file '../../Dev/flatbuffers/tests/monster_test.grpc.fb.cc')
2> W:\Dev\flatbuffers\tests\monster_test.grpc.fb.h(33,7):
2> see declaration of 'MyGame::Example::MonsterStorage'
After inspecting the generated monster_test.grpc.fb.h file, it appears that the declaration of CallbackService is emitted in the wrong scope.
The generated code effectively declares:
MyGame::Example::MonsterStorage::StubInterface::CallbackService
while it should be declared as:
MyGame::Example::MonsterStorage::CallbackService
I verified this behavior both on the current master branch and on commit deb3d93 (the commit that originally introduced this functionality). The problem is reproducible in both cases.
From what I can see, the fix appears to be trivial: the generated class CallbackService; line simply needs to be swapped with the following line containing the closing brace, so that CallbackService is declared in the scope of MonsterStorage rather than inside StubInterface.
Expected behavior
flatc --grpc-callback-api should generate valid C++ code, and the grpctest project should compile successfully.
Actual behavior
Generated code places CallbackService in the wrong scope, causing compilation errors.
When the
--grpc-callback-apioption is used,flatcgenerates invalid C++ code that fails to compile.The
grpctesttest project fails with the following error:After inspecting the generated monster_test.grpc.fb.h file, it appears that the declaration of CallbackService is emitted in the wrong scope.
The generated code effectively declares:
MyGame::Example::MonsterStorage::StubInterface::CallbackServicewhile it should be declared as:
MyGame::Example::MonsterStorage::CallbackServiceI verified this behavior both on the current master branch and on commit deb3d93 (the commit that originally introduced this functionality). The problem is reproducible in both cases.
From what I can see, the fix appears to be trivial: the generated
class CallbackService;line simply needs to be swapped with the following line containing the closing brace, so thatCallbackServiceis declared in the scope ofMonsterStoragerather than insideStubInterface.Expected behavior
flatc --grpc-callback-api should generate valid C++ code, and the grpctest project should compile successfully.
Actual behavior
Generated code places CallbackService in the wrong scope, causing compilation errors.