]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/variadic-ffi.rs
aa58d2e08e94c1c2c3d348f643c83b779c192570
[rust.git] / src / test / compile-fail / variadic-ffi.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 extern "stdcall" {
12     fn printf(_: *u8, ...); //~ ERROR: variadic function must have C calling convention
13 }
14
15 extern {
16     fn foo(f: int, x: u8, ...);
17 }
18
19 extern "C" fn bar(f: int, x: u8) {}
20
21 fn main() {
22     unsafe {
23         foo(); //~ ERROR: this function takes at least 2 parameters but 0 parameters were supplied
24         foo(1); //~ ERROR: this function takes at least 2 parameters but 1 parameter was supplied
25
26         let x: unsafe extern "C" fn(f: int, x: u8) = foo;
27         //~^ ERROR: mismatched types: expected `unsafe extern "C" fn(int, u8)`
28         //          but found `unsafe extern "C" fn(int, u8, ...)`
29         //          (expected non-variadic fn but found variadic function)
30
31         let y: unsafe extern "C" fn(f: int, x: u8, ...) = bar;
32         //~^ ERROR: mismatched types: expected `unsafe extern "C" fn(int, u8, ...)`
33         //          but found `extern "C" extern fn(int, u8)`
34         //          (expected variadic fn but found non-variadic function)
35
36         foo(1, 2, 3f32); //~ ERROR: can't pass an f32 to variadic function, cast to c_double
37         foo(1, 2, true); //~ ERROR: can't pass bool to variadic function, cast to c_int
38         foo(1, 2, 1i8); //~ ERROR: can't pass i8 to variadic function, cast to c_int
39         foo(1, 2, 1u8); //~ ERROR: can't pass u8 to variadic function, cast to c_uint
40         foo(1, 2, 1i16); //~ ERROR: can't pass i16 to variadic function, cast to c_int
41         foo(1, 2, 1u16); //~ ERROR: can't pass u16 to variadic function, cast to c_uint
42     }
43 }