Skip to content

Commit 48c15bd

Browse files
committed
test valid cases of c-variadic function definitions
1 parent 94722ca commit 48c15bd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/ui/c-variadic/valid.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ run-pass
2+
#![feature(c_variadic)]
3+
4+
// In rust (and C23 and above) `...` can be the only argument.
5+
unsafe extern "C" fn only_dot_dot_dot(mut ap: ...) -> i32 {
6+
unsafe { ap.arg() }
7+
}
8+
9+
unsafe extern "C-unwind" fn abi_c_unwind(mut ap: ...) -> i32 {
10+
unsafe { ap.arg() }
11+
}
12+
13+
#[allow(improper_ctypes_definitions)]
14+
unsafe extern "C" fn mix_int_float(mut ap: ...) -> (i64, f64, *const i32, f64) {
15+
(ap.arg(), ap.arg(), ap.arg(), ap.arg())
16+
}
17+
18+
fn main() {
19+
unsafe {
20+
assert_eq!(only_dot_dot_dot(32), 32);
21+
assert_eq!(abi_c_unwind(32), 32);
22+
23+
// Passing more arguments than expected is allowed.
24+
assert_eq!(only_dot_dot_dot(32, 1i64, core::ptr::null::<i32>(), 3.14f64), 32);
25+
26+
let ptr = &14i32 as *const i32;
27+
assert_eq!(mix_int_float(12i64, 13.0f64, ptr, 15.0f64), (12, 13.0, ptr, 15.0));
28+
}
29+
}

0 commit comments

Comments
 (0)