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

Re: [PATCH] config.mak.dev: enable -Wunused-function

From
Duy Nguyen <pclouds@gmail.com>
Date
Oct 18, 2018, 15:48 UTC
Message-ID
<CACsJy8BOL+QOb3Vdh8RKbra-DDbJVyznTbCJgjK5h8L2y0H7yg@mail.gmail.com>
In-Reply-To
<20181018070522.GA29499@sigill.intra.peff.net>
On Thu, Oct 18, 2018 at 9:05 AM Jeff King <peff@peff.net> wrote:
Show 24 quoted lines
>
> We explicitly omitted -Wunused-function when we added
> -Wextra, but there is no need: the current code compiles
> cleanly with it. And it's worth having, since it can let you
> know when there are cascading effects from a cleanup (e.g.,
> deleting one function lets you delete its static helpers).
>
> There are cases where we may need an unused function to
> exist, but we can handle these easily:
>
>   - macro-generated code like commit-slab; there we have the
>     MAYBE_UNUSED annotation to silence the compiler
>
>   - conditional compilation, where we may or may not need a
>     static helper. These generally fall into one of two
>     categories:
>
>       - the call should not be conditional, but rather the
>         function body itself should be (and may just be a
>         no-op on one side of the #if). That keeps the
>         conditional pollution out of the main code.
>
>       - call-chains of static helpers should all be in the
>         same #if block, so they are all-or-nothing

Grouping is not always desired because it could break better function layout. Have a look at read-cache.c where _ieot_extension functions are #if'd because the only call sites are from pthread code (#if'd far away).

In this particular case though I think we should be able to avoid so much #if if we make a wrapper for pthread api that would return an error or something when pthread is not available. But similar situation may happen elsewhere too.

Having said that, if people do consider MAYBE_UNUSED before #if'ing everywhere (and opening up more conditional build problems in future), I think this change is fine.

-- 
Duy
Previous: Jeff KingNext: Jeff King
Message 3 of 13 in “config.mak.dev: enable -Wunused-function”
  1. config.mak.dev: enable -Wunused-functionJeff King, Oct 18, 2018
  2. Jeff KingOct 18, 2018
  3. Duy NguyenOct 18, 2018
  4. Jeff KingOct 18, 2018
  5. thread-utils: better wrapper to avoid #ifdef NO_PTHREADSNguyễn Thái Ngọc Duy, Oct 18, 2018
  6. Jeff KingOct 23, 2018
  7. Junio C HamanoOct 24, 2018
  8. Ben PeartOct 26, 2018
  9. can we deprecate NO_PTHREADS?, was: better wrapper to avoid #ifdef NO_PTHREADSJeff King, Oct 27, 2018
  10. Duy NguyenOct 27, 2018
  11. Jeff KingOct 27, 2018
  12. Ramsay JonesOct 18, 2018
  13. Junio C HamanoOct 19, 2018

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.