Skip to content

flatc generates invalid C++ code with --grpc-callback-api #9130

@Tordan

Description

@Tordan

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.

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions