Skip to content

Commit beaf5e3

Browse files
gumb0axic
authored andcommitted
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.
1 parent 34105da commit beaf5e3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lib/fizzy/types.hpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,34 @@ enum class ExternalKind : uint8_t
324324
// https://webassembly.github.io/spec/core/binary/modules.html#import-section
325325
struct Import
326326
{
327+
Import() = default;
328+
Import(const Import& other) : module(other.module), name(other.name), kind(other.kind)
329+
{
330+
switch (other.kind)
331+
{
332+
case ExternalKind::Function:
333+
desc.function_type_index = other.desc.function_type_index;
334+
break;
335+
case ExternalKind::Table:
336+
desc.table = other.desc.table;
337+
break;
338+
case ExternalKind::Memory:
339+
desc.memory = other.desc.memory;
340+
break;
341+
case ExternalKind::Global:
342+
desc.global = other.desc.global;
343+
break;
344+
}
345+
}
346+
// TODO needs move constructor
347+
327348
std::string module;
328349
std::string name;
329350
ExternalKind kind = ExternalKind::Function;
330-
union
351+
union Desc
331352
{
332-
TypeIdx function_type_index = 0;
353+
Desc() : function_type_index(0) {}
354+
TypeIdx function_type_index;
333355
Memory memory;
334356
GlobalType global;
335357
Table table;

0 commit comments

Comments
 (0)