mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
translate-c: Handle typedef'ed void return type for functions.
Fixes #10356
This commit is contained in:
parent
6d9c02a54f
commit
f4b3f1d602
@ -4824,11 +4824,18 @@ fn qualTypeWasDemotedToOpaque(c: *Context, qt: clang.QualType) bool {
|
||||
|
||||
fn isAnyopaque(qt: clang.QualType) bool {
|
||||
const ty = qt.getTypePtr();
|
||||
if (ty.getTypeClass() == .Builtin) {
|
||||
const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
|
||||
return builtin_ty.getKind() == .Void;
|
||||
switch (ty.getTypeClass()) {
|
||||
.Builtin => {
|
||||
const builtin_ty = @ptrCast(*const clang.BuiltinType, ty);
|
||||
return builtin_ty.getKind() == .Void;
|
||||
},
|
||||
.Typedef => {
|
||||
const typedef_ty = @ptrCast(*const clang.TypedefType, ty);
|
||||
const typedef_decl = typedef_ty.getDecl();
|
||||
return isAnyopaque(typedef_decl.getUnderlyingType());
|
||||
},
|
||||
else => return false,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const FnDeclContext = struct {
|
||||
|
||||
@ -1809,4 +1809,14 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
|
||||
cases.add("Typedef'ed void used as return type. Issue #10356",
|
||||
\\typedef void V;
|
||||
\\V foo(V *f) {}
|
||||
\\int main(void) {
|
||||
\\ int x = 0;
|
||||
\\ foo(&x);
|
||||
\\ return 0;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
|
||||
@ -814,7 +814,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
, &[_][]const u8{
|
||||
\\pub const Foo = anyopaque;
|
||||
,
|
||||
\\pub extern fn fun(a: ?*Foo) Foo;
|
||||
\\pub extern fn fun(a: ?*Foo) void;
|
||||
});
|
||||
|
||||
cases.add("duplicate typedef",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user