Skip to content

Fix missing namespace qualifier in Pack()#8967

Merged
jtdavis777 merged 7 commits into
google:masterfrom
tmimmanuel:fix/cpp-pack-cross-namespace-create-8948
Mar 12, 2026
Merged

Fix missing namespace qualifier in Pack()#8967
jtdavis777 merged 7 commits into
google:masterfrom
tmimmanuel:fix/cpp-pack-cross-namespace-create-8948

Conversation

@tmimmanuel
Copy link
Copy Markdown
Contributor

@tmimmanuel tmimmanuel commented Mar 10, 2026

Summary

  • Fix C++ code generator to emit fully namespace-qualified Create* calls in
    Pack() when referencing tables from different namespaces
  • Add test schema and round-trip Pack/UnPack test for cross-namespace table references

Problem

When a table in namespace foo references a table in namespace native, the
generated Pack() function emitted CreateTableWithNative(...) instead of
native::CreateTableWithNative(...), causing compilation errors.

Fix

Two locations in GenCreateParam in src/idl_gen_cpp.cpp now use
WrapInNameSpace() to qualify Create* calls with the referenced table's
namespace:

  • Scalar table fields (e.g. c1: native.TableWithNative)
  • Vector of table fields (e.g. c2: [native.TableWithNative])

Test plan

  • New cross_namespace_pack_test.fbs schema with cross-namespace table references
  • New CrossNamespacePackTest() in test.cpp verifies Pack/UnPack round-trip
  • flattests passes locally

Closes #8948

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 10, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added python c++ codegen Involving generating code from schema labels Mar 10, 2026
@jtdavis777
Copy link
Copy Markdown
Collaborator

this fix looks great -- it does appear that the new tests don't explicitly validate the interaction with the native API? Though looking over the PR maybe that detail isn't necessary for this bug?

@jtdavis777 jtdavis777 self-requested a review March 11, 2026 15:18
@tmimmanuel
Copy link
Copy Markdown
Contributor Author

you are right that the test doesn't use native_type. The namespace qualification fix is in the table Create* code path in GenCreateParam, which is the same path regardless of whether native_type is set on the referenced table. Adding native_type would require custom native type headers and Pack/UnPack implementations but i think we don't need it for this specific bug.

@jtdavis777 jtdavis777 merged commit e358175 into google:master Mar 12, 2026
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants