Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] : Issue with generated code when naked buffer on a field #8144

Open
ThomasCartier opened this issue Nov 3, 2023 · 1 comment · May be fixed by #8286
Open

[C++] : Issue with generated code when naked buffer on a field #8144

ThomasCartier opened this issue Nov 3, 2023 · 1 comment · May be fixed by #8286
Labels
pr-requested A Pull Request is requested to move the issue forward.

Comments

@ThomasCartier
Copy link

ThomasCartier commented Nov 3, 2023

Hi,

static_assert( FLATBUFFERS_VERSION_MAJOR == 23 &&
               FLATBUFFERS_VERSION_MINOR == 5 &&
               FLATBUFFERS_VERSION_REVISION == 26,
               "Non-compatible flatbuffers version included" );

Given this simplified schema:

table A{

    field1: uint32;

}

table B {

    list : [A] (required, cpp_ptr_type:"naked");

}

root_type B;

The issue is the following function, in the generated file, is written like this:

inline void B::UnPackTo ( BT *_o, const ::flatbuffers::resolver_function_t *_resolver ) const {
        (void)_o;
        (void)_resolver;
        {
                auto _e = list();

                if ( _e ){
                        _o->list.resize( _e->size() );

                        for ( ::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++ ){
                                if ( _o->list[_i] ){
                                        _e->Get( _i )->UnPackTo( _o->list[_i].get(), _resolver ); //here is the error : the .get()
                                }
                                else {
                                        _o->list[_i] = ( _e->Get( _i )->UnPack( _resolver ) );
                                }

                                ;
                        }
                }
                else {
                        _o->list.resize( 0 );
                }
        }
}

My linter pointed the error.
As you can see, _o->list[_i].get() should be _o->list[_i] because we are dealing with raw pointers.

Then it works (just tried).

Thanks

@dbaileychess
Copy link
Collaborator

Seems like a simple fix, can you file a PR?

@dbaileychess dbaileychess added the pr-requested A Pull Request is requested to move the issue forward. label Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-requested A Pull Request is requested to move the issue forward.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants