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++] Native union of struct/table with nested struct is not copyable #6552

Closed
piotrdz opened this issue Apr 8, 2021 · 3 comments
Closed
Labels

Comments

@piotrdz
Copy link
Contributor

piotrdz commented Apr 8, 2021

flatbuffers 1.12.0

Given the following schema:

struct SingleStruct
{
  field: double;
}
struct NestedStruct
{
  nested: SingleStruct;
}
union AnyStruct
{
  SingleStruct,
  NestedStruct
}

I would expect generated native type AnyStructUnion to be copyable for both SingleStruct and NestedStruct.

However, the generated code for AnyStructUnion copy constructor claims otherwise:

inline AnyStructUnion::AnyStructUnion(const AnyStructUnion &u) : type(u.type), value(nullptr) {
  switch (type) {
    case AnyStruct_SingleStruct: {
      value = new SingleStruct(*reinterpret_cast<SingleStruct *>(u.value));
      break;
    }
    case AnyStruct_NestedStruct: {
      FLATBUFFERS_ASSERT(false);  // NestedStruct not copyable.
      break;
    }
    default:
      break;
  }
}

The same problem occurs if NestedStruct is defined as a table.

@aardappel
Copy link
Collaborator

That looks like an oversight in the case of NestedStruct. Care to make a PR to fix it?

For tables I am not sure if we generate a copy constructor. That could of course be added, but may be more work. The default one likely wouldn't work since it may contain unique_ptr etc.

@piotrdz
Copy link
Contributor Author

piotrdz commented May 1, 2021

I created a PR for the nested struct bug.

As for table types, I am hoping that PR #5988 gets merged at some point to address that.

@github-actions
Copy link

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants