summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorTaiju Tsuiki <tzik@users.noreply.github.com>2021-11-19 03:55:11 +0900
committerGitHub <noreply@github.com>2021-11-18 10:55:11 -0800
commit587bbd49a754aa41a0f338fa5e1b672bdc6bfe68 (patch)
tree57592dda70e6f87b0964402d6083cc3aa5c1d518 /samples
parenta9c341545f5248753a9a98c478794328b5ed1b0e (diff)
downloadflatbuffers-587bbd49a754aa41a0f338fa5e1b672bdc6bfe68.tar.gz
flatbuffers-587bbd49a754aa41a0f338fa5e1b672bdc6bfe68.tar.bz2
flatbuffers-587bbd49a754aa41a0f338fa5e1b672bdc6bfe68.zip
[C++] Fix compile failure on Object API union construction for struct member (#6923)
* Add dedicated traits to Object API version of unions. * Add suppression for unused parameters on unions of structs.
Diffstat (limited to 'samples')
-rw-r--r--samples/monster_generated.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/samples/monster_generated.h b/samples/monster_generated.h
index df956e13..efddb8d0 100644
--- a/samples/monster_generated.h
+++ b/samples/monster_generated.h
@@ -103,6 +103,14 @@ template<> struct EquipmentTraits<MyGame::Sample::Weapon> {
static const Equipment enum_value = Equipment_Weapon;
};
+template<typename T> struct EquipmentUnionTraits {
+ static const Equipment enum_value = Equipment_NONE;
+};
+
+template<> struct EquipmentUnionTraits<MyGame::Sample::WeaponT> {
+ static const Equipment enum_value = Equipment_Weapon;
+};
+
struct EquipmentUnion {
Equipment type;
void *value;
@@ -122,9 +130,9 @@ struct EquipmentUnion {
template <typename T>
void Set(T&& val) {
- using RT = typename std::remove_reference<T>::type;
+ typedef typename std::remove_reference<T>::type RT;
Reset();
- type = EquipmentTraits<typename RT::TableType>::enum_value;
+ type = EquipmentUnionTraits<RT>::enum_value;
if (type != Equipment_NONE) {
value = new RT(std::forward<T>(val));
}
@@ -667,6 +675,7 @@ inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuf
}
inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver) {
+ (void)resolver;
switch (type) {
case Equipment_Weapon: {
auto ptr = reinterpret_cast<const MyGame::Sample::Weapon *>(obj);
@@ -677,6 +686,7 @@ inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatb
}
inline flatbuffers::Offset<void> EquipmentUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
+ (void)_rehasher;
switch (type) {
case Equipment_Weapon: {
auto ptr = reinterpret_cast<const MyGame::Sample::WeaponT *>(value);