Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variadic functions with cdecl calling convention. #42249

Merged
merged 1 commit into from
May 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4078,7 +4078,7 @@ register_diagnostics! {
// E0217, // ambiguous associated type, defined in multiple supertraits
// E0218, // no associated type defined
// E0219, // associated type defined in higher-ranked supertrait
// E0222, // Error code E0045 (variadic function must have C calling
// E0222, // Error code E0045 (variadic function must have C or cdecl calling
// convention) duplicate
E0224, // at least one non-builtin train is required for an object type
E0227, // ambiguous lifetime bound, explicit lifetime bound required
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ fn require_c_abi_if_variadic(tcx: TyCtxt,
decl: &hir::FnDecl,
abi: Abi,
span: Span) {
if decl.variadic && abi != Abi::C {
if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
let mut err = struct_span_err!(tcx.sess, span, E0045,
"variadic function must have C calling convention");
err.span_label(span, "variadics require C calling conventions")
.emit();
"variadic function must have C or cdecl calling convention");
err.span_label(span, "variadics require C or cdecl calling convention").emit();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/E0045.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045
//~| NOTE variadics require C calling conventions
//~| NOTE variadics require C or cdecl calling convention

fn main() {
}
6 changes: 4 additions & 2 deletions src/test/compile-fail/variadic-ffi-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn baz(f: extern "cdecl" fn(usize, ...)) {
//~^ ERROR: variadic function must have C calling convention
// ignore-arm stdcall isn't suppported

fn baz(f: extern "stdcall" fn(usize, ...)) {
//~^ ERROR: variadic function must have C or cdecl calling convention
f(22, 44);
}

Expand Down
6 changes: 4 additions & 2 deletions src/test/compile-fail/variadic-ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern "cdecl" {
fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C calling convention
// ignore-arm stdcall isn't suppported

extern "stdcall" {
fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C or cdecl calling
}

extern {
Expand Down