Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Nov 29, 2025


Revisions:

v2
  • Add a few more MAYBE_UNUSED in code touched by recent patches.
$ git range-diff gh/const gh/unused unused 
1:  544f2e24f = 1:  544f2e24f src/: Unname unused parameter of main()
2:  1614d6e63 = 2:  1614d6e63 lib/, src/ tests/: Unname unused parameters in callbacks
3:  ea51596be = 3:  ea51596be lib/logind.c: Unname unused function parameter
4:  5b4e87cf1 ! 4:  5ac58a0aa lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
    @@ lib/log.c: void dolastlog (
        int fd;
        off_t offset;
     
    + ## src/groupmems.c ##
    +@@
    + #include <pwd.h>
    + 
    + #include "alloc/malloc.h"
    ++#include "attr.h"
    + #include "defines.h"
    + #include "groupio.h"
    + #include "prototypes.h"
    +@@ src/groupmems.c: static void process_flags (int argc, char **argv, struct option_flags *flags)
    + 
    + }
    + 
    +-static void check_perms (bool process_selinux)
    ++static void
    ++check_perms(MAYBE_UNUSED bool process_selinux)
    + {
    +   if (!list) {
    + #ifdef USE_PAM
    +
      ## src/newusers.c ##
     @@
      #include "alloc/reallocf.h"
    @@ src/newusers.c: static int update_passwd (struct passwd *pwd, const char *passwo
      {
        const struct spwd *sp;
        struct spwd spent;
    +@@ src/newusers.c: static void check_flags (void)
    +  *
    +  *        It will not return if the user is not allowed.
    +  */
    +-static void check_perms (struct option_flags *flags)
    ++static void
    ++check_perms(MAYBE_UNUSED struct option_flags *flags)
    + {
    + #ifdef ACCT_TOOLS_SETUID
    + #ifdef USE_PAM
5:  730df70cb = 5:  cbe8e96d9 lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
6:  fccf985fa = 6:  3a75e29a1 autogen.sh: CFLAGS: Promose some -Wunused-* to an error
v2b
  • Add some more.
$ git range-diff gh/const gh/unused unused
1:  544f2e24f = 1:  544f2e24f src/: Unname unused parameter of main()
2:  1614d6e63 = 2:  1614d6e63 lib/, src/ tests/: Unname unused parameters in callbacks
3:  ea51596be = 3:  ea51596be lib/logind.c: Unname unused function parameter
4:  5ac58a0aa ! 4:  d6490c042 lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
    @@ Commit message
     
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
    + ## lib/commonio.c ##
    +@@ lib/commonio.c: static int write_all (const struct commonio_db *db)
    + }
    + 
    + 
    +-int commonio_close (struct commonio_db *db, bool process_selinux)
    ++int
    ++commonio_close(struct commonio_db *db, MAYBE_UNUSED bool process_selinux)
    + {
    +   bool         errors = false;
    +   char         buf[1024];
    +
      ## lib/copydir.c ##
     @@ lib/copydir.c: static int copy_hardlink (const struct path_info *dst,
       *        Return 0 on success, -1 on error.
5:  cbe8e96d9 = 5:  d44afef05 lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
6:  3a75e29a1 = 6:  b6333f725 autogen.sh: CFLAGS: Promose some -Wunused-* to an error
v3
$ git rd 
 1:  21105c175 =  1:  21105c175 lib/string/strspn/: Add missing const
 2:  1079f1921 =  2:  1079f1921 autogen.sh: CFLAGS: Promote -Wdiscarded-qualifiers to an error
 3:  544f2e24f =  3:  544f2e24f src/: Unname unused parameter of main()
 4:  1614d6e63 =  4:  1614d6e63 lib/, src/ tests/: Unname unused parameters in callbacks
 5:  ea51596be =  5:  ea51596be lib/logind.c: Unname unused function parameter
 6:  d6490c042 =  6:  d6490c042 lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
 7:  d44afef05 =  7:  d44afef05 lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
 8:  b6333f725 =  8:  b6333f725 autogen.sh: CFLAGS: Promose some -Wunused-* to an error
 -:  --------- >  9:  00303a2d8 lib/sssd.h: sssd_flush_cache(): Define as static inline function
v3b
  • Rebase
$ git rd 
 1:  21105c175 <  -:  --------- lib/string/strspn/: Add missing const
 2:  1079f1921 <  -:  --------- autogen.sh: CFLAGS: Promote -Wdiscarded-qualifiers to an error
 3:  544f2e24f =  1:  5ec29f580 src/: Unname unused parameter of main()
 4:  1614d6e63 =  2:  6c7f051e3 lib/, src/ tests/: Unname unused parameters in callbacks
 5:  ea51596be =  3:  affb78c15 lib/logind.c: Unname unused function parameter
 6:  d6490c042 =  4:  8b7532621 lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
 7:  d44afef05 =  5:  1105aaef9 lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
 8:  b6333f725 =  6:  324264719 autogen.sh: CFLAGS: Promose some -Wunused-* to an error
 9:  00303a2d8 =  7:  1ce93180e lib/sssd.h: sssd_flush_cache(): Define as static inline function
v3c
  • Rebase
  • Add reviewed-by @hallyn, including some notes about a partial objection.
$ git rd 
1:  5ec29f580 ! 1:  7829ab840 src/: Unname unused parameter of main()
    @@ Metadata
      ## Commit message ##
         src/: Unname unused parameter of main()
     
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## src/grpconv.c ##
2:  6c7f051e3 ! 2:  decfeeb28 lib/, src/ tests/: Unname unused parameters in callbacks
    @@ Metadata
      ## Commit message ##
         lib/, src/ tests/: Unname unused parameters in callbacks
     
    +    [Serge: preference to keep the names as a comment, but ok]
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/cleanup_user.c ##
3:  affb78c15 ! 3:  87a54b503 lib/logind.c: Unname unused function parameter
    @@ Metadata
      ## Commit message ##
         lib/logind.c: Unname unused function parameter
     
    +    [Serge: preference to keep the names as a comment, but ok]
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/logind.c ##
4:  8b7532621 ! 4:  ee60b0b6e lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
    @@ Metadata
      ## Commit message ##
         lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
     
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/commonio.c ##
    @@ src/newusers.c: static void check_flags (void)
       *
       *        It will not return if the user is not allowed.
       */
    --static void check_perms (struct option_flags *flags)
    +-static void check_perms(const struct option_flags *flags)
     +static void
    -+check_perms(MAYBE_UNUSED struct option_flags *flags)
    ++check_perms(MAYBE_UNUSED const struct option_flags *flags)
      {
      #ifdef ACCT_TOOLS_SETUID
      #ifdef USE_PAM
5:  1105aaef9 ! 5:  6f1fb7c97 lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
    @@ Metadata
      ## Commit message ##
         lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
     
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/prefix_flag.c ##
6:  324264719 ! 6:  a413c7dc8 autogen.sh: CFLAGS: Promose some -Wunused-* to an error
    @@ Metadata
      ## Commit message ##
         autogen.sh: CFLAGS: Promose some -Wunused-* to an error
     
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## autogen.sh ##
7:  1ce93180e ! 7:  7c8c2b8cc lib/sssd.h: sssd_flush_cache(): Define as static inline function
    @@ Commit message
         below for that.
     
         Link: <https://github.com/shadow-maint/shadow/issues/1221>
    +    Reviewed-by: Serge Hallyn <serge@hallyn.com>
         Signed-off-by: Alejandro Colomar <alx@kernel.org>
     
      ## lib/sssd.h ##
v4
  • Use (void)0 within _Generic(3) to avoid -Wunused-value diagnostics.
$ git rd 
1:  7829ab840 = 1:  7829ab840 src/: Unname unused parameter of main()
2:  decfeeb28 = 2:  decfeeb28 lib/, src/ tests/: Unname unused parameters in callbacks
3:  87a54b503 = 3:  87a54b503 lib/logind.c: Unname unused function parameter
4:  ee60b0b6e = 4:  ee60b0b6e lib/, src/: Add [[gnu::unused]] to parameters used in conditionally-compiled code
5:  6f1fb7c97 = 5:  6f1fb7c97 lib/prefix_flag.c: Add [[gnu::unused]] to variable used in conditionally-compiled code
6:  a413c7dc8 = 6:  a413c7dc8 autogen.sh: CFLAGS: Promose some -Wunused-* to an error
7:  7c8c2b8cc = 7:  7c8c2b8cc lib/sssd.h: sssd_flush_cache(): Define as static inline function
-:  --------- > 8:  f538994d9 lib/search/: Use (void)0 within _Generic(3) to avoid -Wunused-value diagnostics

@alejandro-colomar alejandro-colomar mentioned this pull request Nov 29, 2025
@alejandro-colomar alejandro-colomar changed the title Turn some -Wunused-* diagnostic into errors, and solve them Turn some -Wunused-* diagnostics into errors, and solve them Nov 30, 2025
@alejandro-colomar alejandro-colomar marked this pull request as ready for review December 5, 2025 10:13
@hallyn
Copy link
Member

hallyn commented Dec 5, 2025

This is good stuff, but I would really like to be able to see straight
from the relevant code what this unnamed argument was supposed to be.
No big deal for int main, as we all know it's arguments, but for something
like

129  static int ni_conv (int num_msg,
130                      const struct pam_message **msg,
131                      struct pam_response **resp,
132 -                    MAYBE_UNUSED void *appdata_ptr)
133 +                    void *)
134  {

it's horrible to just see void * there.

What can we do to improve that? I'd be ok with just having

132 -                    void * /* appdata_ptr */)

or implementing an 'always_unused', like

132 -                    void * UNUSED appdata_ptr )

Or even just putting a comment above the function.

Yes, I could look it up, but that's an expensive context switch
while reading the code.

@alejandro-colomar
Copy link
Collaborator Author

This is good stuff, but I would really like to be able to see straight from the relevant code what this unnamed argument was supposed to be. No big deal for int main, as we all know it's arguments, but for something like

129  static int ni_conv (int num_msg,
130                      const struct pam_message **msg,
131                      struct pam_response **resp,
132 -                    MAYBE_UNUSED void *appdata_ptr)
133 +                    void *)
134  {

it's horrible to just see void * there.

What can we do to improve that? I'd be ok with just having

132 -                    void * /* appdata_ptr */)

or implementing an 'always_unused', like

132 -                    void * UNUSED appdata_ptr )

Or even just putting a comment above the function.

Yes, I could look it up, but that's an expensive context switch while reading the code.

I think we shouldn't care what that unnamed argument is. We should think of it as "something that needs to be there because some function pointer demands it but we don't care about it at all".

@hallyn
Copy link
Member

hallyn commented Dec 5, 2025

I think we shouldn't care what that unnamed argument is. We should think of it as "something that needs to be there because some function pointer demands it but we don't care about it at all".

But that's not how the inquisitive human mind works. It'll be
distracting.

Anyway, I'll merge the pr, but am lodging my objection to that bit :)

Thanks.

@alejandro-colomar
Copy link
Collaborator Author

I think we shouldn't care what that unnamed argument is. We should think of it as "something that needs to be there because some function pointer demands it but we don't care about it at all".

But that's not how the inquisitive human mind works. It'll be distracting.

Anyway, I'll merge the pr, but am lodging my objection to that bit :)

Hmmm, I'll keep that partial objection in mind for the future, in case I have any better ideas. :)

Thank you!

Thanks.

@hallyn
Copy link
Member

hallyn commented Dec 5, 2025

(I'm convinced you're working on it, but just to make sure, I was waiting
on you to push the rebase. If you prefer, I'm happy to rebase myself and then
merge)

@alejandro-colomar
Copy link
Collaborator Author

(I'm convinced you're working on it, but just to make sure, I was waiting on you to push the rebase. If you prefer, I'm happy to rebase myself and then merge)

Yup, I'm working on the rebase. :-)

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
[Serge: preference to keep the names as a comment, but ok]
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
[Serge: preference to keep the names as a comment, but ok]
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
…ompiled code

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
…lly-compiled code

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Being a macro, the unused return value triggers a diagnostic.
This probably needs further investigation, but we have the issue linked
below for that.

Link: <shadow-maint#1221>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
@alejandro-colomar
Copy link
Collaborator Author

Done with the rebase, @hallyn. I included Reviewed-by's for you, and some notes about your preference.

…iagnostics

Signed-off-by: Alejandro Colomar <alx@kernel.org>
@hallyn hallyn merged commit 8a5d35c into shadow-maint:master Dec 5, 2025
11 checks passed
@hallyn
Copy link
Member

hallyn commented Dec 5, 2025

Thanks

@alejandro-colomar alejandro-colomar deleted the unused branch December 5, 2025 19:30
@alejandro-colomar alejandro-colomar self-assigned this Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants