mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
fixed void cast and added the last tests
This commit is contained in:
parent
a77b2a0810
commit
5ae400fb39
@ -2784,7 +2784,11 @@ static AstNode *trans_c_style_cast_expr(Context *c, ResultUsed result_used, Tran
|
||||
if (sub_expr_node == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return trans_c_cast(c, stmt->getLocStart(), stmt->getType(), stmt->getSubExpr()->getType(), sub_expr_node);
|
||||
AstNode *cast = trans_c_cast(c, stmt->getLocStart(), stmt->getType(), stmt->getSubExpr()->getType(), sub_expr_node);
|
||||
if (cast == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return maybe_suppress_result(c, result_used, cast);
|
||||
}
|
||||
|
||||
static AstNode *trans_unary_expr_or_type_trait_expr(Context *c, TransScope *scope,
|
||||
|
||||
@ -59,7 +59,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
);
|
||||
}
|
||||
|
||||
cases.add("for loop with var init but empty body",
|
||||
cases.add("predefined expressions",
|
||||
\\void foo(void) {
|
||||
\\ __func__;
|
||||
\\ __FUNCTION__;
|
||||
@ -526,11 +526,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\ return b;
|
||||
\\ else
|
||||
\\ return a;
|
||||
\\
|
||||
\\ if (a < b) ; else ;
|
||||
\\}
|
||||
,
|
||||
\\pub export fn max(a: c_int, b: c_int) c_int {
|
||||
\\ if (a < b) return b;
|
||||
\\ if (a < b) return b else return a;
|
||||
\\ if (a < b) {} else {}
|
||||
\\}
|
||||
);
|
||||
|
||||
@ -772,6 +775,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\}
|
||||
);
|
||||
|
||||
cases.addC("void cast",
|
||||
\\void foo(int a) {
|
||||
\\ (void) a;
|
||||
\\}
|
||||
,
|
||||
\\pub export fn foo(a: c_int) void {
|
||||
\\ _ = a;
|
||||
\\}
|
||||
);
|
||||
|
||||
cases.addC("implicit cast to void *",
|
||||
\\void *foo(unsigned short *x) {
|
||||
\\ return x;
|
||||
@ -1472,21 +1485,53 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\pub export fn bar() void {}
|
||||
);
|
||||
|
||||
cases.addC("u integer suffix after 0 (zero) in macro definition", "#define ZERO 0U", "pub const ZERO = c_uint(0);");
|
||||
cases.addC(
|
||||
"u integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0U",
|
||||
"pub const ZERO = c_uint(0);",
|
||||
);
|
||||
|
||||
cases.addC("l integer suffix after 0 (zero) in macro definition", "#define ZERO 0L", "pub const ZERO = c_long(0);");
|
||||
cases.addC(
|
||||
"l integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0L",
|
||||
"pub const ZERO = c_long(0);",
|
||||
);
|
||||
|
||||
cases.addC("ul integer suffix after 0 (zero) in macro definition", "#define ZERO 0UL", "pub const ZERO = c_ulong(0);");
|
||||
cases.addC(
|
||||
"ul integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0UL",
|
||||
"pub const ZERO = c_ulong(0);",
|
||||
);
|
||||
|
||||
cases.addC("lu integer suffix after 0 (zero) in macro definition", "#define ZERO 0LU", "pub const ZERO = c_ulong(0);");
|
||||
cases.addC(
|
||||
"lu integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0LU",
|
||||
"pub const ZERO = c_ulong(0);",
|
||||
);
|
||||
|
||||
cases.addC("ll integer suffix after 0 (zero) in macro definition", "#define ZERO 0LL", "pub const ZERO = c_longlong(0);");
|
||||
cases.addC(
|
||||
"ll integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0LL",
|
||||
"pub const ZERO = c_longlong(0);",
|
||||
);
|
||||
|
||||
cases.addC("ull integer suffix after 0 (zero) in macro definition", "#define ZERO 0ULL", "pub const ZERO = c_ulonglong(0);");
|
||||
cases.addC(
|
||||
"ull integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0ULL",
|
||||
"pub const ZERO = c_ulonglong(0);",
|
||||
);
|
||||
|
||||
cases.addC("llu integer suffix after 0 (zero) in macro definition", "#define ZERO 0LLU", "pub const ZERO = c_ulonglong(0);");
|
||||
cases.addC(
|
||||
"llu integer suffix after 0 (zero) in macro definition",
|
||||
"#define ZERO 0LLU",
|
||||
"pub const ZERO = c_ulonglong(0);",
|
||||
);
|
||||
|
||||
cases.addC("bitwise not on u-suffixed 0 (zero) in macro definition", "#define NOT_ZERO (~0U)", "pub const NOT_ZERO = ~c_uint(0);");
|
||||
cases.addC(
|
||||
"bitwise not on u-suffixed 0 (zero) in macro definition",
|
||||
"#define NOT_ZERO (~0U)",
|
||||
"pub const NOT_ZERO = ~c_uint(0);",
|
||||
);
|
||||
|
||||
// cases.add("empty array with initializer",
|
||||
// "int a[4] = {};"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user