]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/variadic-ffi.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / compile-fail / variadic-ffi.rs
CommitLineData
1a4d82fc
JJ
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
11extern "stdcall" {
12 fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C calling convention
13}
14
15extern {
16 fn foo(f: isize, x: u8, ...);
17}
18
19extern "C" fn bar(f: isize, x: u8) {}
20
21fn 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: isize, x: u8) = foo;
85aaf69f
SL
27 //~^ ERROR: mismatched types
28 //~| expected `unsafe extern "C" fn(isize, u8)`
29 //~| found `unsafe extern "C" fn(isize, u8, ...)`
30 //~| expected non-variadic fn
31 //~| found variadic function
1a4d82fc 32
c34b1796 33 let y: extern "C" fn(f: isize, x: u8, ...) = bar;
85aaf69f 34 //~^ ERROR: mismatched types
c34b1796 35 //~| expected `extern "C" fn(isize, u8, ...)`
85aaf69f
SL
36 //~| found `extern "C" fn(isize, u8) {bar}`
37 //~| expected variadic fn
38 //~| found non-variadic function
1a4d82fc
JJ
39
40 foo(1, 2, 3f32); //~ ERROR: can't pass an f32 to variadic function, cast to c_double
41 foo(1, 2, true); //~ ERROR: can't pass bool to variadic function, cast to c_int
42 foo(1, 2, 1i8); //~ ERROR: can't pass i8 to variadic function, cast to c_int
43 foo(1, 2, 1u8); //~ ERROR: can't pass u8 to variadic function, cast to c_uint
44 foo(1, 2, 1i16); //~ ERROR: can't pass i16 to variadic function, cast to c_int
45 foo(1, 2, 1u16); //~ ERROR: can't pass u16 to variadic function, cast to c_uint
46 }
47}