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

Unable to call variadic function with no named parameters even though it is useful since C23 #123773

Closed
HomelikeBrick42 opened this issue Apr 11, 2024 · 1 comment · Fixed by #124048
Assignees
Labels
A-FFI Area: Foreign function interface (FFI) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@HomelikeBrick42
Copy link
Contributor

HomelikeBrick42 commented Apr 11, 2024

You have always been able to define variadic functions in C with no named parameters, but until C23 it was not useful because you could never access those arguments
Since C23 the va_start macro in C has been changed to no longer require a parameter name, so now being able to call variadic functions with no named parameters is actually useful

extern "C" {
    fn foo(...);
}

I would expect this to compile, if there was a function foo defined in C like so

void foo(...) { // the ... is optional pre-c23, but since C23 its required to make the function variadic
    // whatever implementation
}

But instead this does not compile

error: C-variadic function must be declared with at least one named argument
 --> src\lib.rs:2:12
  |
2 |     fn foo(...);
  |            ^^^

Meta

rustc --version --verbose:

binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6
@HomelikeBrick42 HomelikeBrick42 added the C-bug Category: This is a bug. label Apr 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 11, 2024
@fmease fmease added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-FFI Area: Foreign function interface (FFI) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 12, 2024
@veera-sivarajan
Copy link
Contributor

@rustbot claim

bors added a commit to rust-lang-ci/rust that referenced this issue May 26, 2024
…riadics, r=compiler-errors

Support C23's Variadics Without a Named Parameter

Fixes rust-lang#123773

This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

This will not break any existing code as mentioned in the proposal
document: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
jhpratt added a commit to jhpratt/rust that referenced this issue May 26, 2024
…variadics, r=compiler-errors

Support C23's Variadics Without a Named Parameter

Fixes rust-lang#123773

This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

This will not break any existing code as mentioned in the proposal
document: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
@bors bors closed this as completed in 866630d May 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 27, 2024
Rollup merge of rust-lang#124048 - veera-sivarajan:bugfix-123773-c23-variadics, r=compiler-errors

Support C23's Variadics Without a Named Parameter

Fixes rust-lang#123773

This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

This will not break any existing code as mentioned in the proposal
document: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-FFI Area: Foreign function interface (FFI) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants