Skip to content

Commit

Permalink
Add explicit constructors to Import
Browse files Browse the repository at this point in the history
This fixes Import being not copy-constructible in GCC older than 8.3, where std::optional is not trivially constructible.
  • Loading branch information
gumb0 committed Jan 28, 2021
1 parent a4d8fe2 commit e17721c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/fizzy/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e17721c

Please sign in to comment.