allow extern structs to have stdcallcc function pointers

closes #1536
This commit is contained in:
Andrew Kelley 2018-09-17 11:22:30 -04:00
parent dd5b2d1b04
commit 9c9eefc841
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 16 additions and 1 deletions

View File

@ -1470,7 +1470,8 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) {
case ZigTypeIdArray:
return type_allowed_in_extern(g, type_entry->data.array.child_type);
case ZigTypeIdFn:
return type_entry->data.fn.fn_type_id.cc == CallingConventionC;
return type_entry->data.fn.fn_type_id.cc == CallingConventionC ||
type_entry->data.fn.fn_type_id.cc == CallingConventionStdcall;
case ZigTypeIdPointer:
if (type_size(g, type_entry) == 0)
return false;

View File

@ -191,3 +191,17 @@ test "return inner function which references comptime variable of outer function
var func = outer(10);
assert(func(3) == 7);
}
test "extern struct with stdcallcc fn pointer" {
const S = extern struct {
ptr: stdcallcc fn () i32,
stdcallcc fn foo() i32 {
return 1234;
}
};
var s: S = undefined;
s.ptr = S.foo;
assert(s.ptr() == 1234);
}