From 6024830162a8def9f7e38826695e9ece76c3f5f8 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 8 Jun 2026 13:48:49 +0100 Subject: [PATCH 1/2] Fix untyped K&R parameter --- compiler/src/dmd/hdrgen.d | 12 +++++++----- compiler/test/fail_compilation/diag23177.d | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index b456f6cc52ca..5e8b70d2b448 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -3656,6 +3656,13 @@ const(char)* parameterToChars(Parameter parameter, TypeFunction tf, bool fullQua private void parametersToBuffer(ParameterList pl, ref OutBuffer buf, ref HdrGenState hgs) { buf.put('('); + if (pl.varargs == VarArg.KRvariadic) + { + if (!hgs.hdrgen) + buf.put(""); + buf.put(')'); + return; + } foreach (i; 0 .. pl.length) { if (i) @@ -3665,12 +3672,7 @@ private void parametersToBuffer(ParameterList pl, ref OutBuffer buf, ref HdrGenS final switch (pl.varargs) { case VarArg.none: - break; - case VarArg.KRvariadic: - // Diagnostic-only spelling; header/.di output keeps plain `()`. - if (!hgs.hdrgen) - buf.put(""); break; case VarArg.variadic: diff --git a/compiler/test/fail_compilation/diag23177.d b/compiler/test/fail_compilation/diag23177.d index 2bec867df896..af57579f0640 100644 --- a/compiler/test/fail_compilation/diag23177.d +++ b/compiler/test/fail_compilation/diag23177.d @@ -5,10 +5,10 @@ TEST_OUTPUT: --- fail_compilation/diag23177.d(25): Error: function `run1` is not callable using argument types `(extern (C) int function())` -fail_compilation/diag23177.d(25): cannot pass argument `& callback` of type `extern (C) int function()` to parameter `extern (C) int function() fn` -fail_compilation/imports/imp23177.c(4): `imp23177.run1(extern (C) int function() fn)` declared here -fail_compilation/diag23177.d(26): Error: function `run2` is not callable using argument types `(extern (C) int function(int a))` -fail_compilation/diag23177.d(26): cannot pass argument `& f` of type `extern (C) int function(int a)` to parameter `extern (C) int function(int a) fn` +fail_compilation/diag23177.d(25): cannot pass argument `& callback` of type `extern (C) int function()` to parameter `extern (C) int function() fn` +fail_compilation/imports/imp23177.c(4): `imp23177.run1(extern (C) int function() fn)` declared here +fail_compilation/diag23177.d(26): Error: function `run2` is not callable using argument types `(extern (C) int function())` +fail_compilation/diag23177.d(26): cannot pass argument `& f` of type `extern (C) int function()` to parameter `extern (C) int function(int a) fn` fail_compilation/imports/imp23177.c(14): `imp23177.run2(extern (C) int function(int a) fn)` declared here --- */ From 8f5ec86af25994b44ff12e6eb5cfbba06626bdbe Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 8 Jun 2026 16:56:46 +0100 Subject: [PATCH 2/2] Use C23 variadic syntax --- compiler/src/dmd/hdrgen.d | 2 +- compiler/test/fail_compilation/diag23177.d | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index 5e8b70d2b448..6c9120677e85 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -3659,7 +3659,7 @@ private void parametersToBuffer(ParameterList pl, ref OutBuffer buf, ref HdrGenS if (pl.varargs == VarArg.KRvariadic) { if (!hgs.hdrgen) - buf.put(""); + buf.put("..."); // essentially C23 variadic with no named parameter buf.put(')'); return; } diff --git a/compiler/test/fail_compilation/diag23177.d b/compiler/test/fail_compilation/diag23177.d index af57579f0640..aa20cd7a7223 100644 --- a/compiler/test/fail_compilation/diag23177.d +++ b/compiler/test/fail_compilation/diag23177.d @@ -5,10 +5,10 @@ TEST_OUTPUT: --- fail_compilation/diag23177.d(25): Error: function `run1` is not callable using argument types `(extern (C) int function())` -fail_compilation/diag23177.d(25): cannot pass argument `& callback` of type `extern (C) int function()` to parameter `extern (C) int function() fn` -fail_compilation/imports/imp23177.c(4): `imp23177.run1(extern (C) int function() fn)` declared here -fail_compilation/diag23177.d(26): Error: function `run2` is not callable using argument types `(extern (C) int function())` -fail_compilation/diag23177.d(26): cannot pass argument `& f` of type `extern (C) int function()` to parameter `extern (C) int function(int a) fn` +fail_compilation/diag23177.d(25): cannot pass argument `& callback` of type `extern (C) int function()` to parameter `extern (C) int function(...) fn` +fail_compilation/imports/imp23177.c(4): `imp23177.run1(extern (C) int function(...) fn)` declared here +fail_compilation/diag23177.d(26): Error: function `run2` is not callable using argument types `(extern (C) int function(...))` +fail_compilation/diag23177.d(26): cannot pass argument `& f` of type `extern (C) int function(...)` to parameter `extern (C) int function(int a) fn` fail_compilation/imports/imp23177.c(14): `imp23177.run2(extern (C) int function(int a) fn)` declared here --- */