From 45a2b07cbd83c14c233bafd0f7d850bc52f9aa24 Mon Sep 17 00:00:00 2001 From: Vladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com> Date: Fri, 13 Mar 2020 02:07:27 +0700 Subject: Remove `noexcept` qualifier copy-ctor of `union` type (#5800) (#5802) - Remove `noexcept` qualifier from generated 'union' copy-constructor - Remove `noexcept` qualifier from generated 'union' assign-operator --- samples/monster_generated.h | 6 +++--- src/idl_gen_cpp.cpp | 9 +++------ tests/cpp17/generated_cpp17/monster_test_generated.h | 18 +++++++++--------- tests/monster_test_generated.h | 18 +++++++++--------- tests/union_vector/union_vector_generated.h | 6 +++--- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 6c5267c9..4e49d5f9 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -111,8 +111,8 @@ struct EquipmentUnion { EquipmentUnion(EquipmentUnion&& u) FLATBUFFERS_NOEXCEPT : type(Equipment_NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - EquipmentUnion(const EquipmentUnion &) FLATBUFFERS_NOEXCEPT; - EquipmentUnion &operator=(const EquipmentUnion &u) FLATBUFFERS_NOEXCEPT + EquipmentUnion(const EquipmentUnion &); + EquipmentUnion &operator=(const EquipmentUnion &u) { EquipmentUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } EquipmentUnion &operator=(EquipmentUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -694,7 +694,7 @@ inline flatbuffers::Offset EquipmentUnion::Pack(flatbuffers::FlatBufferBui } } -inline EquipmentUnion::EquipmentUnion(const EquipmentUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline EquipmentUnion::EquipmentUnion(const EquipmentUnion &u) : type(u.type), value(nullptr) { switch (type) { case Equipment_Weapon: { value = new MyGame::Sample::WeaponT(*reinterpret_cast(u.value)); diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 9903ae49..f78ee268 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -1227,10 +1227,8 @@ class CppGenerator : public BaseGenerator { code_ += " {{NAME}}Union({{NAME}}Union&& u) FLATBUFFERS_NOEXCEPT :"; code_ += " type({{NONE}}), value(nullptr)"; code_ += " { std::swap(type, u.type); std::swap(value, u.value); }"; - code_ += " {{NAME}}Union(const {{NAME}}Union &) FLATBUFFERS_NOEXCEPT;"; - code_ += - " {{NAME}}Union &operator=(const {{NAME}}Union &u) " - "FLATBUFFERS_NOEXCEPT"; + code_ += " {{NAME}}Union(const {{NAME}}Union &);"; + code_ += " {{NAME}}Union &operator=(const {{NAME}}Union &u)"; code_ += " { {{NAME}}Union t(u); std::swap(type, t.type); std::swap(value, " "t.value); return *this; }"; @@ -1469,8 +1467,7 @@ class CppGenerator : public BaseGenerator { // Union copy constructor code_ += "inline {{ENUM_NAME}}Union::{{ENUM_NAME}}Union(const " - "{{ENUM_NAME}}Union &u) FLATBUFFERS_NOEXCEPT : type(u.type), " - "value(nullptr) {"; + "{{ENUM_NAME}}Union &u) : type(u.type), value(nullptr) {"; code_ += " switch (type) {"; for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { diff --git a/tests/cpp17/generated_cpp17/monster_test_generated.h b/tests/cpp17/generated_cpp17/monster_test_generated.h index d32d84a4..928d8dd0 100644 --- a/tests/cpp17/generated_cpp17/monster_test_generated.h +++ b/tests/cpp17/generated_cpp17/monster_test_generated.h @@ -216,8 +216,8 @@ struct AnyUnion { AnyUnion(AnyUnion&& u) FLATBUFFERS_NOEXCEPT : type(Any::NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - AnyUnion(const AnyUnion &) FLATBUFFERS_NOEXCEPT; - AnyUnion &operator=(const AnyUnion &u) FLATBUFFERS_NOEXCEPT + AnyUnion(const AnyUnion &); + AnyUnion &operator=(const AnyUnion &u) { AnyUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } AnyUnion &operator=(AnyUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -329,8 +329,8 @@ struct AnyUniqueAliasesUnion { AnyUniqueAliasesUnion(AnyUniqueAliasesUnion&& u) FLATBUFFERS_NOEXCEPT : type(AnyUniqueAliases::NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &) FLATBUFFERS_NOEXCEPT; - AnyUniqueAliasesUnion &operator=(const AnyUniqueAliasesUnion &u) FLATBUFFERS_NOEXCEPT + AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &); + AnyUniqueAliasesUnion &operator=(const AnyUniqueAliasesUnion &u) { AnyUniqueAliasesUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } AnyUniqueAliasesUnion &operator=(AnyUniqueAliasesUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -426,8 +426,8 @@ struct AnyAmbiguousAliasesUnion { AnyAmbiguousAliasesUnion(AnyAmbiguousAliasesUnion&& u) FLATBUFFERS_NOEXCEPT : type(AnyAmbiguousAliases::NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &) FLATBUFFERS_NOEXCEPT; - AnyAmbiguousAliasesUnion &operator=(const AnyAmbiguousAliasesUnion &u) FLATBUFFERS_NOEXCEPT + AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &); + AnyAmbiguousAliasesUnion &operator=(const AnyAmbiguousAliasesUnion &u) { AnyAmbiguousAliasesUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } AnyAmbiguousAliasesUnion &operator=(AnyAmbiguousAliasesUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -2630,7 +2630,7 @@ inline flatbuffers::Offset AnyUnion::Pack(flatbuffers::FlatBufferBuilder & } } -inline AnyUnion::AnyUnion(const AnyUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline AnyUnion::AnyUnion(const AnyUnion &u) : type(u.type), value(nullptr) { switch (type) { case Any::Monster: { FLATBUFFERS_ASSERT(false); // MyGame::Example::MonsterT not copyable. @@ -2741,7 +2741,7 @@ inline flatbuffers::Offset AnyUniqueAliasesUnion::Pack(flatbuffers::FlatBu } } -inline AnyUniqueAliasesUnion::AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline AnyUniqueAliasesUnion::AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &u) : type(u.type), value(nullptr) { switch (type) { case AnyUniqueAliases::M: { FLATBUFFERS_ASSERT(false); // MyGame::Example::MonsterT not copyable. @@ -2852,7 +2852,7 @@ inline flatbuffers::Offset AnyAmbiguousAliasesUnion::Pack(flatbuffers::Fla } } -inline AnyAmbiguousAliasesUnion::AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline AnyAmbiguousAliasesUnion::AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &u) : type(u.type), value(nullptr) { switch (type) { case AnyAmbiguousAliases::M1: { FLATBUFFERS_ASSERT(false); // MyGame::Example::MonsterT not copyable. diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index 2808dc70..b0512a26 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -244,8 +244,8 @@ struct AnyUnion { AnyUnion(AnyUnion&& u) FLATBUFFERS_NOEXCEPT : type(Any_NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - AnyUnion(const AnyUnion &) FLATBUFFERS_NOEXCEPT; - AnyUnion &operator=(const AnyUnion &u) FLATBUFFERS_NOEXCEPT + AnyUnion(const AnyUnion &); + AnyUnion &operator=(const AnyUnion &u) { AnyUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } AnyUnion &operator=(AnyUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -386,8 +386,8 @@ struct AnyUniqueAliasesUnion { AnyUniqueAliasesUnion(AnyUniqueAliasesUnion&& u) FLATBUFFERS_NOEXCEPT : type(AnyUniqueAliases_NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &) FLATBUFFERS_NOEXCEPT; - AnyUniqueAliasesUnion &operator=(const AnyUniqueAliasesUnion &u) FLATBUFFERS_NOEXCEPT + AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &); + AnyUniqueAliasesUnion &operator=(const AnyUniqueAliasesUnion &u) { AnyUniqueAliasesUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } AnyUniqueAliasesUnion &operator=(AnyUniqueAliasesUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -512,8 +512,8 @@ struct AnyAmbiguousAliasesUnion { AnyAmbiguousAliasesUnion(AnyAmbiguousAliasesUnion&& u) FLATBUFFERS_NOEXCEPT : type(AnyAmbiguousAliases_NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &) FLATBUFFERS_NOEXCEPT; - AnyAmbiguousAliasesUnion &operator=(const AnyAmbiguousAliasesUnion &u) FLATBUFFERS_NOEXCEPT + AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &); + AnyAmbiguousAliasesUnion &operator=(const AnyAmbiguousAliasesUnion &u) { AnyAmbiguousAliasesUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } AnyAmbiguousAliasesUnion &operator=(AnyAmbiguousAliasesUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -2865,7 +2865,7 @@ inline flatbuffers::Offset AnyUnion::Pack(flatbuffers::FlatBufferBuilder & } } -inline AnyUnion::AnyUnion(const AnyUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline AnyUnion::AnyUnion(const AnyUnion &u) : type(u.type), value(nullptr) { switch (type) { case Any_Monster: { FLATBUFFERS_ASSERT(false); // MyGame::Example::MonsterT not copyable. @@ -2976,7 +2976,7 @@ inline flatbuffers::Offset AnyUniqueAliasesUnion::Pack(flatbuffers::FlatBu } } -inline AnyUniqueAliasesUnion::AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline AnyUniqueAliasesUnion::AnyUniqueAliasesUnion(const AnyUniqueAliasesUnion &u) : type(u.type), value(nullptr) { switch (type) { case AnyUniqueAliases_M: { FLATBUFFERS_ASSERT(false); // MyGame::Example::MonsterT not copyable. @@ -3087,7 +3087,7 @@ inline flatbuffers::Offset AnyAmbiguousAliasesUnion::Pack(flatbuffers::Fla } } -inline AnyAmbiguousAliasesUnion::AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline AnyAmbiguousAliasesUnion::AnyAmbiguousAliasesUnion(const AnyAmbiguousAliasesUnion &u) : type(u.type), value(nullptr) { switch (type) { case AnyAmbiguousAliases_M1: { FLATBUFFERS_ASSERT(false); // MyGame::Example::MonsterT not copyable. diff --git a/tests/union_vector/union_vector_generated.h b/tests/union_vector/union_vector_generated.h index d65c77cd..a03f7227 100644 --- a/tests/union_vector/union_vector_generated.h +++ b/tests/union_vector/union_vector_generated.h @@ -88,8 +88,8 @@ struct CharacterUnion { CharacterUnion(CharacterUnion&& u) FLATBUFFERS_NOEXCEPT : type(Character_NONE), value(nullptr) { std::swap(type, u.type); std::swap(value, u.value); } - CharacterUnion(const CharacterUnion &) FLATBUFFERS_NOEXCEPT; - CharacterUnion &operator=(const CharacterUnion &u) FLATBUFFERS_NOEXCEPT + CharacterUnion(const CharacterUnion &); + CharacterUnion &operator=(const CharacterUnion &u) { CharacterUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; } CharacterUnion &operator=(CharacterUnion &&u) FLATBUFFERS_NOEXCEPT { std::swap(type, u.type); std::swap(value, u.value); return *this; } @@ -642,7 +642,7 @@ inline flatbuffers::Offset CharacterUnion::Pack(flatbuffers::FlatBufferBui } } -inline CharacterUnion::CharacterUnion(const CharacterUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) { +inline CharacterUnion::CharacterUnion(const CharacterUnion &u) : type(u.type), value(nullptr) { switch (type) { case Character_MuLan: { value = new AttackerT(*reinterpret_cast(u.value)); -- cgit v1.2.3