[c++] flatc version 23.5.26 : generated c++ fails to compile if the fbs namespace path ends in `flatbuffers`
Given this foo.fbs input file
namespace com.awesomcompany.foo.flatbuffers;
table Bar {
name:string;
value:int;
}
root_type Bar ;
and this cpp file that uses Bar after compiling with flatc --cpp --gen-object-api foo.fbs
#include <iostream>
#include "foo_generated.h"
using namespace com::awesomcompany::foo::flatbuffers;
void test() {
std::cout << "Creating bar " << std::endl;
BarT bar;
}
c++ compilation fails with a bunch of errors due to namespace clashes between the generated foo::flatbuffers namespace and the flatbuffers namespace that y'all own.
./foo_generated.h:34:8: error: use of enum ‘FlatBuffersVTableOffset’ without previous declaration
34 | enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from ./include/flatbuffers/array.h:23,
from ./include/flatbuffers/flatbuffers.h:24,
from ./foo_generated.h:7,
from ./foo.cpp:2:
./include/flatbuffers/base.h:158:61: error: ‘voffset_t’ is not a member of ‘com::awesomcompany::foo::flatbuffers’; did you mean ‘flatbuffers::voffset_t’?
158 | #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
| ^~~~~~~~~
./foo_generated.h:34:32: note: in expansion of macro ‘FLATBUFFERS_VTABLE_UNDERLYING_TYPE’
34 | enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
... about 4 more errors like these
Best workaround is to simply not use a flatbuffers suffix. I expect this to be closed without fixing as it doesn't seem like a critical issue, but I thought it was worth mentioning at least.
btw, these errors are the inspiration for #8111 . I don't mind if the C++ types lack the foo::flatbuffers namespace, but I would like to bury generated java files in a .flatbuffers package suffix. Implement #8111 and I really don't care about this issue at all.