From e17721c7b4e34df01be01ec83e7861793c91fce0 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Thu, 28 Jan 2021 12:07:53 +0100 Subject: [PATCH] Add explicit constructors to Import This fixes Import being not copy-constructible in GCC older than 8.3, where std::optional is not trivially constructible. --- lib/fizzy/types.hpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/fizzy/types.hpp b/lib/fizzy/types.hpp index 7f4272159c..d9a81947fb 100644 --- a/lib/fizzy/types.hpp +++ b/lib/fizzy/types.hpp @@ -324,12 +324,34 @@ enum class ExternalKind : uint8_t // https://webassembly.github.io/spec/core/binary/modules.html#import-section struct Import { + Import() = default; + Import(const Import& other) : module(other.module), name(other.name), kind(other.kind) + { + switch(other.kind) + { + case ExternalKind::Function: + desc.function_type_index = other.desc.function_type_index; + break; + case ExternalKind::Table: + desc.table = other.desc.table; + break; + case ExternalKind::Memory: + desc.memory = other.desc.memory; + break; + case ExternalKind::Global: + desc.global = other.desc.global; + break; + } + } + // TODO needs move constructor + std::string module; std::string name; ExternalKind kind = ExternalKind::Function; - union + union Desc { - TypeIdx function_type_index = 0; + Desc() : function_type_index(0) {} + TypeIdx function_type_index; Memory memory; GlobalType global; Table table;