diff options
| author | Alexandros Naskos <alex_naskos@hotmail.com> | 2020-10-03 12:51:39 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-03 12:51:39 +0300 |
| commit | e31cc80130ee7e4b61b63d1d1a0fc0a84fbb15ff (patch) | |
| tree | 9d08c75af32a03e28a50ee0c5594c44cabf46099 /src/stage1/analyze.cpp | |
| parent | b5034bd7765565f838466d8b212140097a1eefba (diff) | |
| parent | 65016dff322c9344cc5e7bf9d6ad6907de940c7f (diff) | |
| download | zig-e31cc80130ee7e4b61b63d1d1a0fc0a84fbb15ff.tar.gz zig-e31cc80130ee7e4b61b63d1d1a0fc0a84fbb15ff.zip | |
Merge pull request #6427 from tadeokondrak/enums-explicit-tag-type-extern-allowed
Allow enums with explicit extern-allowed tag types in extern types
Diffstat (limited to 'src/stage1/analyze.cpp')
| -rw-r--r-- | src/stage1/analyze.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index 369c284684..64251c1f0c 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -1802,10 +1802,18 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { } return type_allowed_in_extern(g, child_type, result); } - case ZigTypeIdEnum: - *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || - type_entry->data.enumeration.layout == ContainerLayoutPacked; - return ErrorNone; + case ZigTypeIdEnum: { + if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) + return err; + ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type; + if (type_entry->data.enumeration.has_explicit_tag_type) { + return type_allowed_in_extern(g, tag_int_type, result); + } else { + *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || + type_entry->data.enumeration.layout == ContainerLayoutPacked; + return ErrorNone; + } + } case ZigTypeIdUnion: *result = type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked; @@ -2639,9 +2647,11 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { if (decl_node->type == NodeTypeContainerDecl) { if (decl_node->data.container_decl.init_arg_expr != nullptr) { wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); + enum_type->data.enumeration.has_explicit_tag_type = true; } } else { wanted_tag_int_type = enum_type->data.enumeration.tag_int_type; + enum_type->data.enumeration.has_explicit_tag_type = true; } if (wanted_tag_int_type != nullptr) { |
