From 90ac77e4085444a456e2ce1f03b4d2546c43ca3d Mon Sep 17 00:00:00 2001 From: Manu Evans Date: Thu, 5 Mar 2026 20:15:03 +1000 Subject: [PATCH] Complement to the unused_params PR. --- spec/function.dd | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/function.dd b/spec/function.dd index f4d44bdd53..0388eaffb0 100644 --- a/spec/function.dd +++ b/spec/function.dd @@ -1844,6 +1844,40 @@ pure void f() $(DDSUBLINK spec/declaration, alias-function, with default values).) +$(H3 $(LNAME2 unused-params, Unused Function Parameters)) + + $(P With the $(D -preview=warnunusedparams) compiler flag, the compiler + warns about named function parameters that are never used within the + function body. This is often an indication of a bug or dead code.) + +--- +void foo(int x, int y) // Warning: function parameter `y` is never used +{ + return x * 2; +} +--- + + $(P To intentionally leave a parameter unused $(LPAREN)ie; to match an + interface or callback signature$(RPAREN), omit the parameter name:) + +--- +void callback(int x, int) // no warning for unnamed parameter +{ + use(x); +} +--- + + $(P Alternatively, $(D cast$(LPAREN)void$(RPAREN)) can be used to explicitly mark + a named parameter as intentionally unused, particularly around conditional compilation:) + +--- +void bar(int x, int y) +{ + cast(void)y; // suppress unused parameter warning + use(x); +} +--- + $(H3 $(LNAME2 return-ref-parameters, Return Ref Parameters)) $(P Return ref parameters are used with