Skip to content

[C++] Tables containing native tables from a different namespace missing namespace in Pack function #8948

@souryavarenya

Description

@souryavarenya

As the title mentions, when using a native table from another namespace inside another table, the generated code is missing the namespace in the Pack() function. See the below reproduction scenario.


Minimal example

// native.hpp

#include <vector>

struct MyNativeInterface {
    std::vector<int> data;
};
// native.fbs
// flatc --cpp --gen-object-api native.fbs

native_include "native.hpp";

namespace native;

table TableWithNative (native_type: "native::MyNativeInterface") {
    data: [int];
}
// consumer.fbs
// flatc --cpp --gen-object-api consumer.fbs

include "native.fbs";

namespace foo;

table Consumer {
    c1: native.TableWithNative;
    c2: [native.TableWithNative] (native_inline);
}

The generated header for the consumer.fbs is as below:

// consumer_generated.h

//...
#include "native_generated.h"

namespace foo {
// ...

inline ::flatbuffers::Offset<Consumer> Consumer::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const ConsumerT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
  (void)_rehasher;
  (void)_o;
  struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const ConsumerT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
  auto _c1 = _o->c1 ? CreateTableWithNative(_fbb, _o->c1.get(), _rehasher) : 0; // <-- no good! should be native::CreateTableWithNative
  auto _c2 = _o->c2.size() ? _fbb.CreateVector<::flatbuffers::Offset<native::TableWithNative>> (_o->c2.size(), [](size_t i, _VectorArgs *__va) { return CreateTableWithNative(*__va->__fbb, &(__va->__o->c2[i]), __va->__rehasher); }, &_va ) : 0;
  return foo::CreateConsumer(
      _fbb,
      _c1,
      _c2);
}

// NOTE: It should be 'native::CreateTableWithNative', and not just 'CreateTableWithNative' in both 'c1' and 'c2' above.

// ...
}

It should be native::CreateTableWithNative, and not just CreateTableWithNative in both c1 and c2 above.


Tagging @cosmith-nvidia due to relevance to this implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++pr-requestedA Pull Request is requested to move the issue forward.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions