| ... | @@ -725,11 +725,15 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No | ... | @@ -725,11 +725,15 @@ fn transEnumDecl(c: *Context, enum_decl: *const ZigClangEnumDecl) Error!?*ast.No |
| 725 | }; | 725 | }; |
| 726 | | 726 | |
| 727 | const int_type = ZigClangEnumDecl_getIntegerType(enum_decl); | 727 | const int_type = ZigClangEnumDecl_getIntegerType(enum_decl); |
| | 728 | // The underlying type may be null in case of forward-declared enum |
| | 729 | // types, while that's not ISO-C compliant many compilers allow this and |
| | 730 | // default to the usual integer type used for all the enums. |
| 728 | | 731 | |
| 729 | // TODO only emit this tag type if the enum tag type is not the default. | 732 | // TODO only emit this tag type if the enum tag type is not the default. |
| 730 | // I don't know what the default is, need to figure out how clang is deciding. | 733 | // I don't know what the default is, need to figure out how clang is deciding. |
| 731 | // it appears to at least be different across gcc/msvc | 734 | // it appears to at least be different across gcc/msvc |
| 732 | if (!isCBuiltinType(int_type, .UInt) and | 735 | if (int_type.ptr != null and |
| | 736 | !isCBuiltinType(int_type, .UInt) and |
| 733 | !isCBuiltinType(int_type, .Int)) | 737 | !isCBuiltinType(int_type, .Int)) |
| 734 | { | 738 | { |
| 735 | _ = try appendToken(c, .LParen, "("); | 739 | _ = try appendToken(c, .LParen, "("); |
| ... | @@ -1555,8 +1559,7 @@ fn transCCast( | ... | @@ -1555,8 +1559,7 @@ fn transCCast( |
| 1555 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ZigClangQualType_getTypePtr(dst_type)); | 1559 | const elaborated_ty = @ptrCast(*const ZigClangElaboratedType, ZigClangQualType_getTypePtr(dst_type)); |
| 1556 | return transCCast(rp, scope, loc, ZigClangElaboratedType_getNamedType(elaborated_ty), src_type, expr); | 1560 | return transCCast(rp, scope, loc, ZigClangElaboratedType_getNamedType(elaborated_ty), src_type, expr); |
| 1557 | } | 1561 | } |
| 1558 | if (ZigClangQualType_getTypeClass(dst_type) == .Enum) | 1562 | if (ZigClangQualType_getTypeClass(dst_type) == .Enum) { |
| 1559 | { | | |
| 1560 | const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToEnum"); | 1563 | const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToEnum"); |
| 1561 | try builtin_node.params.push(try transQualType(rp, dst_type, loc)); | 1564 | try builtin_node.params.push(try transQualType(rp, dst_type, loc)); |
| 1562 | _ = try appendToken(rp.c, .Comma, ","); | 1565 | _ = try appendToken(rp.c, .Comma, ","); |