Skip to content

Commit 1f28fcd

Browse files
committedNov 14, 2017
parsec supports C NULL to pointer implicit cast
1 parent a890380 commit 1f28fcd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎src/parsec.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,8 @@ static AstNode *trans_implicit_cast_expr(Context *c, AstNode *block, ImplicitCas
12671267
node->data.fn_call_expr.params.append(target_node);
12681268
return node;
12691269
}
1270+
case CK_NullToPointer:
1271+
return trans_create_node(c, NodeTypeNullLiteral);
12701272
case CK_Dependent:
12711273
emit_warning(c, stmt->getLocStart(), "TODO handle C translation cast CK_Dependent");
12721274
return nullptr;
@@ -1291,9 +1293,6 @@ static AstNode *trans_implicit_cast_expr(Context *c, AstNode *block, ImplicitCas
12911293
case CK_ToUnion:
12921294
emit_warning(c, stmt->getLocStart(), "TODO handle C translation cast CK_ToUnion");
12931295
return nullptr;
1294-
case CK_NullToPointer:
1295-
emit_warning(c, stmt->getLocStart(), "TODO handle C translation cast CK_NullToPointer");
1296-
return nullptr;
12971296
case CK_NullToMemberPointer:
12981297
emit_warning(c, stmt->getLocStart(), "TODO handle C translation cast CK_NullToMemberPointer");
12991298
return nullptr;

‎test/parsec.zig

+10
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,16 @@ pub fn addCases(cases: &tests.ParseCContext) {
596596
\\ return @sizeOf(c_int);
597597
\\}
598598
);
599+
600+
cases.addC("null pointer implicit cast",
601+
\\int* foo(void) {
602+
\\ return 0;
603+
\\}
604+
,
605+
\\export fn foo() -> ?&c_int {
606+
\\ return null;
607+
\\}
608+
);
599609
}
600610

601611

0 commit comments

Comments
 (0)
Please sign in to comment.