mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-21 19:08:28 +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:
@@ -35,7 +35,7 @@ inline const flatbuffers::TypeTable *BookReaderTypeTable();
|
||||
|
||||
inline const flatbuffers::TypeTable *MovieTypeTable();
|
||||
|
||||
enum Character {
|
||||
enum Character : uint8_t {
|
||||
Character_NONE = 0,
|
||||
Character_MuLan = 1,
|
||||
Character_Rapunzel = 2,
|
||||
@@ -271,10 +271,7 @@ struct AttackerT : public flatbuffers::NativeTable {
|
||||
static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
|
||||
return "AttackerT";
|
||||
}
|
||||
int32_t sword_attack_damage;
|
||||
AttackerT()
|
||||
: sword_attack_damage(0) {
|
||||
}
|
||||
int32_t sword_attack_damage = 0;
|
||||
};
|
||||
|
||||
inline bool operator==(const AttackerT &lhs, const AttackerT &rhs) {
|
||||
@@ -348,10 +345,8 @@ struct MovieT : public flatbuffers::NativeTable {
|
||||
static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
|
||||
return "MovieT";
|
||||
}
|
||||
CharacterUnion main_character;
|
||||
std::vector<CharacterUnion> characters;
|
||||
MovieT() {
|
||||
}
|
||||
CharacterUnion main_character{};
|
||||
std::vector<CharacterUnion> characters{};
|
||||
};
|
||||
|
||||
inline bool operator==(const MovieT &lhs, const MovieT &rhs) {
|
||||
@@ -496,7 +491,7 @@ inline flatbuffers::Offset<Movie> CreateMovieDirect(
|
||||
flatbuffers::Offset<Movie> CreateMovie(flatbuffers::FlatBufferBuilder &_fbb, const MovieT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
inline AttackerT *Attacker::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<AttackerT> _o = flatbuffers::unique_ptr<AttackerT>(new AttackerT());
|
||||
auto _o = std::unique_ptr<AttackerT>(new AttackerT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
@@ -522,7 +517,7 @@ inline flatbuffers::Offset<Attacker> CreateAttacker(flatbuffers::FlatBufferBuild
|
||||
}
|
||||
|
||||
inline MovieT *Movie::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
flatbuffers::unique_ptr<MovieT> _o = flatbuffers::unique_ptr<MovieT>(new MovieT());
|
||||
auto _o = std::unique_ptr<MovieT>(new MovieT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user