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++] Unqualified reference to "flatbuffers" namespace should be qualified #5308
Comments
Alternatively, we could error out on a namespace ending in Everyone on the planet uses |
AFAIK, you can also pass namespaces types to IMO, it's worth doing, mainly for allowing users the option of nesting a But yes, erroring out on namespaces ending with namespace their { namespace flatbuffers { namespace nested {
// ...
} } } But error out in this case would prevent the user from making it work: With namespace their { namespace flatbuffers { namespace nested {
namespace flatbuffers = ::flatbuffers;
} } }
#include "flatbuffers_generated.h" |
I am not a fan of people using Do you want to make a PR to add |
This issue has been automatically marked as stale because it has not had activity for 1 year. It will be automatically closed if no further activity occurs. To keep it open, simply post a new comment. Maintainers will re-open on new activity. Thank you for your contributions. |
In the generated code, references to library namespaces (specifically
flatbuffers
) should be qualified rather than unqualified. Currently, if the user namespaces their.fbs
file, they could run into trouble:Generates something like this:
The references to
flatbuffers::Table
and all other functions and types will fail, since it finds the::their::flatbuffers
namespace rather than::flatbuffers
. Instead of generatingflatbuffers::...
, we should be generating::flatbuffers::...
.For example,
flatbuffers/src/idl_gen_cpp.cpp
Line 358 in 5b43e4b
should look like
code_ += " return ::flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
This applies to all other library references, including the standard library. Although it would be weird, users could conceivably have a
std
namespace nested inside their own namespace, which would causestd::vector
to fail. For example, this case can fail:Generates:
This normally works, but if the user has:
This perfectly compliant code would cause the flatc-generated code to fail to find
std::vector
, as the unqualified lookup forstd
stops at findingtheir::std
.Therefore, any reference to a type which is not one which flatc generates should use a fully qualified namespace with a leading
::
to ensure we always get the correct type. This includes types passed in with--cpp-str-type
and the like.The text was updated successfully, but these errors were encountered: