Skip to content

C-variadic functions may not be extern "C-unwind" #126836

Closed
@asomers

Description

@asomers

Overview

Using the unstable c_variadic feature, functions may be variadic as long as they have an extern "C" ABI. That used to be a reasonable restriction. However, after #74990 , extern "C" isn't as useful as it used to be. Now, any function that might panic needs to be extern "C-unwind". This may not technically be a compiler regression. But it's certainly a regression in functionality. Previously, Mockall was able to mock C variadic functions. Now, it cannot. Would it be possible to relax that restriction?

Example

I tried this code:

#![feature(c_variadic)]

pub extern "C-unwind" fn foo(x: i32, y: i32, ...) -> i32 {
    unimplemented!()
}

I expected to see this happen: It should compile ok.

Instead, this happened: It fails with this error:

error: only foreign or `unsafe extern "C"` functions may be C-variadic

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (c1b336cb6 2024-06-21)
binary: rustc
commit-hash: c1b336cb6b491b3be02cd821774f03af4992f413
commit-date: 2024-06-21
host: x86_64-unknown-freebsd
release: 1.81.0-nightly
LLVM version: 18.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-c_unwind`#![feature(c_unwind)]`F-c_variadic`#![feature(c_variadic)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions