git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 6/6] config.mak.dev: enable -Wunused-parameter by default

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 28, 2024, 05:56 UTC
Message-ID
<CAPig+cQLr+vAzkt8UJNVCeE8osGEcEfFunG36oqxa0k8JamJzQ@mail.gmail.com>
In-Reply-To
<20240828040049.GF3999193@coredump.intra.peff.net>
On Wed, Aug 28, 2024 at 12:01 AM Jeff King <peff@peff.net> wrote:
Show 28 quoted lines
> Having now removed or annotated all of the unused function parameters in
> our code base, I found that each instance falls into one of three
> categories:
>
>   1. ignoring the parameter is a bug (e.g., a function takes a ptr/len
>      pair, but ignores the length). Detecting these helps us find the
>      bugs.
>
>   2. the parameter is unnecessary (and usually left over from a
>      refactoring or earlier iteration of a patches series). Removing
>      these cleans up the code.
>
>   3. the function has to conform to a specific interface (because it's
>      used via a function pointer, or matches something on the other side
>      of an #ifdef). These ones are annoying, but annotating them with
>      UNUSED is not too bad (especially if the compiler tells you about
>      the problem promptly).
> [...]
> And since the code base is now at a spot where we compile cleanly with
> -Wunused-parameter, turning it on will make it the responsibility of
> individual patch writers going forward.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> diff --git a/config.mak.dev b/config.mak.dev
> @@ -54,7 +54,6 @@ ifeq ($(filter extra-all,$(DEVOPTS)),)
>  DEVELOPER_CFLAGS += -Wno-sign-compare
> -DEVELOPER_CFLAGS += -Wno-unused-parameter

What is the expectation regarding newcomers to the project or even people who have not been following this topic and its cousins? Documentation/CodingGuidelines recommends enabling DEVELOPER mode, which is good, but this change means that such people may now be hit with a compiler complaint which they don't necessarily know how to deal with in the legitimate case #3 (described above). Should CodingGuidelines be updated to mention "UNUSED" and the circumstances under which it should be used?

Previous: Jeff KingNext: Patrick Steinhardt
Message 8 of 13 in “unused parameters: the final countdown”
  1. 0/6 unused parameters: the final countdownJeff King, Aug 28, 2024
  2. 1/6 gc: mark unused config parameter in virtual functionsJeff King, Aug 28, 2024
  3. 2/6 t-reftable-readwrite: mark unused parameter in callback functionJeff King, Aug 28, 2024
  4. 3/6 compat: disable -Wunused-parameter in 3rd-party codeJeff King, Aug 28, 2024
  5. 4/6 compat: disable -Wunused-parameter in win32/headless.cJeff King, Aug 28, 2024
  6. 5/6 compat: mark unused parameters in win32/mingw functionsJeff King, Aug 28, 2024
  7. 6/6 config.mak.dev: enable -Wunused-parameter by defaultJeff King, Aug 28, 2024
  8. Eric SunshineAug 28, 2024
  9. Patrick SteinhardtAug 28, 2024
  10. 7/6 CodingGuidelines: mention -Wunused-parameter and UNUSEDJeff King, Aug 28, 2024
  11. Eric SunshineAug 28, 2024
  12. Junio C HamanoAug 28, 2024
  13. Jeff KingAug 28, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.