mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-25 18:18:40 +00:00
[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:
@@ -107,7 +107,7 @@ inline const flatbuffers::TypeTable *MonsterTypeTable();
|
||||
inline const flatbuffers::TypeTable *TypeAliasesTypeTable();
|
||||
|
||||
/// Composite components of Monster color.
|
||||
enum Color {
|
||||
enum Color : uint8_t {
|
||||
Color_Red = 1,
|
||||
/// \brief color Green
|
||||
/// Green is bit_flag with value (1u << 1)
|
||||
@@ -148,7 +148,7 @@ inline const char *EnumNameColor(Color e) {
|
||||
return EnumNamesColor()[index];
|
||||
}
|
||||
|
||||
enum Race {
|
||||
enum Race : int8_t {
|
||||
Race_None = -1,
|
||||
Race_Human = 0,
|
||||
Race_Dwarf = 1,
|
||||
@@ -184,7 +184,7 @@ inline const char *EnumNameRace(Race e) {
|
||||
return EnumNamesRace()[index];
|
||||
}
|
||||
|
||||
enum Any {
|
||||
enum Any : uint8_t {
|
||||
Any_NONE = 0,
|
||||
Any_Monster = 1,
|
||||
Any_TestSimpleTableWithEnum = 2,
|
||||
@@ -326,7 +326,7 @@ inline bool operator!=(const AnyUnion &lhs, const AnyUnion &rhs) {
|
||||
bool VerifyAny(flatbuffers::Verifier &verifier, const void *obj, Any type);
|
||||
bool VerifyAnyVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
enum AnyUniqueAliases {
|
||||
enum AnyUniqueAliases : uint8_t {
|
||||
AnyUniqueAliases_NONE = 0,
|
||||
AnyUniqueAliases_M = 1,
|
||||
AnyUniqueAliases_TS = 2,
|
||||
@@ -468,7 +468,7 @@ inline bool operator!=(const AnyUniqueAliasesUnion &lhs, const AnyUniqueAliasesU
|
||||
bool VerifyAnyUniqueAliases(flatbuffers::Verifier &verifier, const void *obj, AnyUniqueAliases type);
|
||||
bool VerifyAnyUniqueAliasesVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
enum AnyAmbiguousAliases {
|
||||
enum AnyAmbiguousAliases : uint8_t {
|
||||
AnyAmbiguousAliases_NONE = 0,
|
||||
AnyAmbiguousAliases_M1 = 1,
|
||||
AnyAmbiguousAliases_M2 = 2,
|
||||
@@ -781,8 +781,6 @@ inline bool operator!=(const Ability &lhs, const Ability &rhs) {
|
||||
|
||||
struct InParentNamespaceT : public flatbuffers::NativeTable {
|
||||
typedef InParentNamespace TableType;
|
||||
InParentNamespaceT() {
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const InParentNamespaceT &, const InParentNamespaceT &) {
|
||||
@@ -836,8 +834,6 @@ namespace Example2 {
|
||||
|
||||
struct MonsterT : public flatbuffers::NativeTable {
|
||||
typedef Monster TableType;
|
||||
MonsterT() {
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const MonsterT &, const MonsterT &) {
|
||||
@@ -893,10 +889,7 @@ namespace Example {
|
||||
|
||||
struct TestSimpleTableWithEnumT : public flatbuffers::NativeTable {
|
||||
typedef TestSimpleTableWithEnum TableType;
|
||||
MyGame::Example::Color color;
|
||||
TestSimpleTableWithEnumT()
|
||||
: color(MyGame::Example::Color_Green) {
|
||||
}
|
||||
MyGame::Example::Color color = MyGame::Example::Color_Green;
|
||||
};
|
||||
|
||||
inline bool operator==(const TestSimpleTableWithEnumT &lhs, const TestSimpleTableWithEnumT &rhs) {
|
||||
@@ -964,13 +957,9 @@ flatbuffers::Offset<TestSimpleTableWithEnum> CreateTestSimpleTableWithEnum(flatb
|
||||
|
||||
struct StatT : public flatbuffers::NativeTable {
|
||||
typedef Stat TableType;
|
||||
std::string id;
|
||||
int64_t val;
|
||||
uint16_t count;
|
||||
StatT()
|
||||
: val(0),
|
||||
count(0) {
|
||||
}
|
||||
std::string id{};
|
||||
int64_t val = 0;
|
||||
uint16_t count = 0;
|
||||
};
|
||||
|
||||
inline bool operator==(const StatT &lhs, const StatT &rhs) {
|
||||
@@ -1080,10 +1069,7 @@ flatbuffers::Offset<Stat> CreateStat(flatbuffers::FlatBufferBuilder &_fbb, const
|
||||
|
||||
struct ReferrableT : public flatbuffers::NativeTable {
|
||||
typedef Referrable TableType;
|
||||
uint64_t id;
|
||||
ReferrableT()
|
||||
: id(0) {
|
||||
}
|
||||
uint64_t id = 0;
|
||||
};
|
||||
|
||||
inline bool operator==(const ReferrableT &lhs, const ReferrableT &rhs) {
|
||||
@@ -1157,73 +1143,52 @@ flatbuffers::Offset<Referrable> CreateReferrable(flatbuffers::FlatBufferBuilder
|
||||
|
||||
struct MonsterT : public flatbuffers::NativeTable {
|
||||
typedef Monster TableType;
|
||||
flatbuffers::unique_ptr<MyGame::Example::Vec3> pos;
|
||||
int16_t mana;
|
||||
int16_t hp;
|
||||
std::string name;
|
||||
std::vector<uint8_t> inventory;
|
||||
MyGame::Example::Color color;
|
||||
MyGame::Example::AnyUnion test;
|
||||
std::vector<MyGame::Example::Test> test4;
|
||||
std::vector<std::string> testarrayofstring;
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Example::MonsterT>> testarrayoftables;
|
||||
flatbuffers::unique_ptr<MyGame::Example::MonsterT> enemy;
|
||||
std::vector<uint8_t> testnestedflatbuffer;
|
||||
flatbuffers::unique_ptr<MyGame::Example::StatT> testempty;
|
||||
bool testbool;
|
||||
int32_t testhashs32_fnv1;
|
||||
uint32_t testhashu32_fnv1;
|
||||
int64_t testhashs64_fnv1;
|
||||
uint64_t testhashu64_fnv1;
|
||||
int32_t testhashs32_fnv1a;
|
||||
Stat *testhashu32_fnv1a;
|
||||
int64_t testhashs64_fnv1a;
|
||||
uint64_t testhashu64_fnv1a;
|
||||
std::vector<bool> testarrayofbools;
|
||||
float testf;
|
||||
float testf2;
|
||||
float testf3;
|
||||
std::vector<std::string> testarrayofstring2;
|
||||
std::vector<MyGame::Example::Ability> testarrayofsortedstruct;
|
||||
std::vector<uint8_t> flex;
|
||||
std::vector<MyGame::Example::Test> test5;
|
||||
std::vector<int64_t> vector_of_longs;
|
||||
std::vector<double> vector_of_doubles;
|
||||
flatbuffers::unique_ptr<MyGame::InParentNamespaceT> parent_namespace_test;
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Example::ReferrableT>> vector_of_referrables;
|
||||
ReferrableT *single_weak_reference;
|
||||
std::vector<ReferrableT *> vector_of_weak_references;
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Example::ReferrableT>> vector_of_strong_referrables;
|
||||
ReferrableT *co_owning_reference;
|
||||
std::vector<flatbuffers::unique_ptr<ReferrableT>> vector_of_co_owning_references;
|
||||
ReferrableT *non_owning_reference;
|
||||
std::vector<ReferrableT *> vector_of_non_owning_references;
|
||||
MyGame::Example::AnyUniqueAliasesUnion any_unique;
|
||||
MyGame::Example::AnyAmbiguousAliasesUnion any_ambiguous;
|
||||
std::vector<MyGame::Example::Color> vector_of_enums;
|
||||
MyGame::Example::Race signed_enum;
|
||||
std::vector<uint8_t> testrequirednestedflatbuffer;
|
||||
MonsterT()
|
||||
: mana(150),
|
||||
hp(100),
|
||||
color(MyGame::Example::Color_Blue),
|
||||
testbool(false),
|
||||
testhashs32_fnv1(0),
|
||||
testhashu32_fnv1(0),
|
||||
testhashs64_fnv1(0),
|
||||
testhashu64_fnv1(0),
|
||||
testhashs32_fnv1a(0),
|
||||
testhashu32_fnv1a(nullptr),
|
||||
testhashs64_fnv1a(0),
|
||||
testhashu64_fnv1a(0),
|
||||
testf(3.14159f),
|
||||
testf2(3.0f),
|
||||
testf3(0.0f),
|
||||
single_weak_reference(nullptr),
|
||||
co_owning_reference(nullptr),
|
||||
non_owning_reference(nullptr),
|
||||
signed_enum(MyGame::Example::Race_None) {
|
||||
}
|
||||
flatbuffers::unique_ptr<MyGame::Example::Vec3> pos{};
|
||||
int16_t mana = 150;
|
||||
int16_t hp = 100;
|
||||
std::string name{};
|
||||
std::vector<uint8_t> inventory{};
|
||||
MyGame::Example::Color color = MyGame::Example::Color_Blue;
|
||||
MyGame::Example::AnyUnion test{};
|
||||
std::vector<MyGame::Example::Test> test4{};
|
||||
std::vector<std::string> testarrayofstring{};
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Example::MonsterT>> testarrayoftables{};
|
||||
flatbuffers::unique_ptr<MyGame::Example::MonsterT> enemy{};
|
||||
std::vector<uint8_t> testnestedflatbuffer{};
|
||||
flatbuffers::unique_ptr<MyGame::Example::StatT> testempty{};
|
||||
bool testbool = false;
|
||||
int32_t testhashs32_fnv1 = 0;
|
||||
uint32_t testhashu32_fnv1 = 0;
|
||||
int64_t testhashs64_fnv1 = 0;
|
||||
uint64_t testhashu64_fnv1 = 0;
|
||||
int32_t testhashs32_fnv1a = 0;
|
||||
Stat *testhashu32_fnv1a = nullptr;
|
||||
int64_t testhashs64_fnv1a = 0;
|
||||
uint64_t testhashu64_fnv1a = 0;
|
||||
std::vector<bool> testarrayofbools{};
|
||||
float testf = 3.14159f;
|
||||
float testf2 = 3.0f;
|
||||
float testf3 = 0.0f;
|
||||
std::vector<std::string> testarrayofstring2{};
|
||||
std::vector<MyGame::Example::Ability> testarrayofsortedstruct{};
|
||||
std::vector<uint8_t> flex{};
|
||||
std::vector<MyGame::Example::Test> test5{};
|
||||
std::vector<int64_t> vector_of_longs{};
|
||||
std::vector<double> vector_of_doubles{};
|
||||
flatbuffers::unique_ptr<MyGame::InParentNamespaceT> parent_namespace_test{};
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Example::ReferrableT>> vector_of_referrables{};
|
||||
ReferrableT *single_weak_reference = nullptr;
|
||||
std::vector<ReferrableT *> vector_of_weak_references{};
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Example::ReferrableT>> vector_of_strong_referrables{};
|
||||
ReferrableT *co_owning_reference = nullptr;
|
||||
std::vector<flatbuffers::unique_ptr<ReferrableT>> vector_of_co_owning_references{};
|
||||
ReferrableT *non_owning_reference = nullptr;
|
||||
std::vector<ReferrableT *> vector_of_non_owning_references{};
|
||||
MyGame::Example::AnyUniqueAliasesUnion any_unique{};
|
||||
MyGame::Example::AnyAmbiguousAliasesUnion any_ambiguous{};
|
||||
std::vector<MyGame::Example::Color> vector_of_enums{};
|
||||
MyGame::Example::Race signed_enum = MyGame::Example::Race_None;
|
||||
std::vector<uint8_t> testrequirednestedflatbuffer{};
|
||||
};
|
||||
|
||||
inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
@@ -2178,30 +2143,18 @@ flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb,
|
||||
|
||||
struct TypeAliasesT : public flatbuffers::NativeTable {
|
||||
typedef TypeAliases TableType;
|
||||
int8_t i8;
|
||||
uint8_t u8;
|
||||
int16_t i16;
|
||||
uint16_t u16;
|
||||
int32_t i32;
|
||||
uint32_t u32;
|
||||
int64_t i64;
|
||||
uint64_t u64;
|
||||
float f32;
|
||||
double f64;
|
||||
std::vector<int8_t> v8;
|
||||
std::vector<double> vf64;
|
||||
TypeAliasesT()
|
||||
: i8(0),
|
||||
u8(0),
|
||||
i16(0),
|
||||
u16(0),
|
||||
i32(0),
|
||||
u32(0),
|
||||
i64(0),
|
||||
u64(0),
|
||||
f32(0.0f),
|
||||
f64(0.0) {
|
||||
}
|
||||
int8_t i8 = 0;
|
||||
uint8_t u8 = 0;
|
||||
int16_t i16 = 0;
|
||||
uint16_t u16 = 0;
|
||||
int32_t i32 = 0;
|
||||
uint32_t u32 = 0;
|
||||
int64_t i64 = 0;
|
||||
uint64_t u64 = 0;
|
||||
float f32 = 0.0f;
|
||||
double f64 = 0.0;
|
||||
std::vector<int8_t> v8{};
|
||||
std::vector<double> vf64{};
|
||||
};
|
||||
|
||||
inline bool operator==(const TypeAliasesT &lhs, const TypeAliasesT &rhs) {
|
||||
@@ -2458,7 +2411,7 @@ flatbuffers::Offset<TypeAliases> CreateTypeAliases(flatbuffers::FlatBufferBuilde
|
||||
} // namespace Example
|
||||
|
||||
inline InParentNamespaceT *InParentNamespace::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::InParentNamespaceT> _o = flatbuffers::unique_ptr<MyGame::InParentNamespaceT>(new InParentNamespaceT());
|
||||
auto _o = std::unique_ptr<InParentNamespaceT>(new InParentNamespaceT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -2483,7 +2436,7 @@ inline flatbuffers::Offset<InParentNamespace> CreateInParentNamespace(flatbuffer
|
||||
namespace Example2 {
|
||||
|
||||
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::Example2::MonsterT> _o = flatbuffers::unique_ptr<MyGame::Example2::MonsterT>(new MonsterT());
|
||||
auto _o = std::unique_ptr<MonsterT>(new MonsterT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -2510,7 +2463,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
||||
namespace Example {
|
||||
|
||||
inline TestSimpleTableWithEnumT *TestSimpleTableWithEnum::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::Example::TestSimpleTableWithEnumT> _o = flatbuffers::unique_ptr<MyGame::Example::TestSimpleTableWithEnumT>(new TestSimpleTableWithEnumT());
|
||||
auto _o = std::unique_ptr<TestSimpleTableWithEnumT>(new TestSimpleTableWithEnumT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -2536,7 +2489,7 @@ inline flatbuffers::Offset<TestSimpleTableWithEnum> CreateTestSimpleTableWithEnu
|
||||
}
|
||||
|
||||
inline StatT *Stat::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::Example::StatT> _o = flatbuffers::unique_ptr<MyGame::Example::StatT>(new StatT());
|
||||
auto _o = std::unique_ptr<StatT>(new StatT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -2568,7 +2521,7 @@ inline flatbuffers::Offset<Stat> CreateStat(flatbuffers::FlatBufferBuilder &_fbb
|
||||
}
|
||||
|
||||
inline ReferrableT *Referrable::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::Example::ReferrableT> _o = flatbuffers::unique_ptr<MyGame::Example::ReferrableT>(new ReferrableT());
|
||||
auto _o = std::unique_ptr<ReferrableT>(new ReferrableT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -2594,7 +2547,7 @@ inline flatbuffers::Offset<Referrable> CreateReferrable(flatbuffers::FlatBufferB
|
||||
}
|
||||
|
||||
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::Example::MonsterT> _o = flatbuffers::unique_ptr<MyGame::Example::MonsterT>(new MonsterT());
|
||||
auto _o = std::unique_ptr<MonsterT>(new MonsterT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -2771,7 +2724,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
||||
}
|
||||
|
||||
inline TypeAliasesT *TypeAliases::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MyGame::Example::TypeAliasesT> _o = flatbuffers::unique_ptr<MyGame::Example::TypeAliasesT>(new TypeAliasesT());
|
||||
auto _o = std::unique_ptr<TypeAliasesT>(new TypeAliasesT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user