[C++] Switch flatc to --cpp-std c++11 C++ code generator (#6306)

Prior to this commit the default C++ code generator was `c++0x`.
A code generated with `c++0x` code-gen might have a vulnerability (undefined behavior) connected evolution of enums in a schema. This UB could break the backward compatibility if previously generated code casts an unknown enumerator to enum type that knows nothing about future enumerators added to the schema.

The main differences between `c++0x` and `c++11`:

- generated enums use explicitly declared underlying type;
- generated object-API tables don't declare default ctor() explicitly, instead of it default data member initializers are generated.

Please use `flatc --cpp-std c++0x` option for backward compatibility with old compilers.
This commit is contained in:
Vladimir Glavnyy
2020-12-08 02:19:36 +07:00
committed by GitHub
parent 8d9eae9ac9
commit 7f33cf682a
13 changed files with 168 additions and 287 deletions

View File

@@ -24,7 +24,7 @@ inline const flatbuffers::TypeTable *TableInNestedNSTypeTable();
inline const flatbuffers::TypeTable *StructInNestedNSTypeTable();
enum EnumInNestedNS {
enum EnumInNestedNS : int8_t {
EnumInNestedNS_A = 0,
EnumInNestedNS_B = 1,
EnumInNestedNS_C = 2,
@@ -108,10 +108,7 @@ struct TableInNestedNST : public flatbuffers::NativeTable {
static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
return "NamespaceA.NamespaceB.TableInNestedNST";
}
int32_t foo;
TableInNestedNST()
: foo(0) {
}
int32_t foo = 0;
};
inline bool operator==(const TableInNestedNST &lhs, const TableInNestedNST &rhs) {
@@ -181,7 +178,7 @@ inline flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS(
flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS(flatbuffers::FlatBufferBuilder &_fbb, const TableInNestedNST *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
inline TableInNestedNST *TableInNestedNS::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST> _o = flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST>(new TableInNestedNST());
auto _o = std::unique_ptr<TableInNestedNST>(new TableInNestedNST());
UnPackTo(_o.get(), _resolver);
return _o.release();
}