flatc generates invalid C++ code with `--grpc-callback-api`
- Dominant language
- C++
- Stars
- 26.5k
- Forks
- 3.7k
- PR merge metrics
- No merged PRs in 30d
Description
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 deb3d934 (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.
Contributor guide
Assessment
This issue has not been assessed yet.