translate-c: Translate FnDecl's that appear within functions

This commit is contained in:
Evan Haas 2021-05-07 10:23:43 -07:00 committed by Veikka Tuominen
parent e8236551ab
commit d321a4b765
2 changed files with 15 additions and 0 deletions

View File

@ -1682,6 +1682,9 @@ fn transDeclStmtOne(
.Enum => {
try transEnumDecl(c, scope, @ptrCast(*const clang.EnumDecl, decl));
},
.Function => {
try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));
},
else => |kind| return fail(
c,
error.UnsupportedTranslation,

View File

@ -3529,4 +3529,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\warning: unable to translate function, demoted to extern
\\pub extern fn initialize() void;
});
cases.add("Function prototype declared within function",
\\int foo(void) {
\\ extern int bar(int, int);
\\ return bar(1, 2);
\\}
, &[_][]const u8{
\\pub extern fn bar(c_int, c_int) c_int;
\\pub export fn foo() c_int {
\\ return bar(@as(c_int, 1), @as(c_int, 2));
\\}
});
}