https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87588

            Bug ID: 87588
           Summary: gcc does not warn about unused about unused variable
                    which references to itself
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at breakpoint dot cc
  Target Milestone: ---

The .c file:
---->8-----
struct list {
        struct list *prev, *next;
};

struct mutex {
        struct list waiters;
};

static struct mutex mutex = \
        {.waiters = {.prev = &mutex.waiters, .next = &mutex.waiters}};

static int a;
static int *b = &a;
---->8-----

produces:
  gcc -o a.o a.c -c -O2 -Wall 
  a.c:14:13: warning: 'b' defined but not used [-Wunused-variable]
  14 | static int *b = &a;
     |             ^

Would it be possible to also warn that the variable 'mutex' is unused? Except
that its member (.list.prev) is referenced to itself, it is not used outside of
that "initialization" construct.

Reply via email to