https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115027
Bug ID: 115027
Summary: Missing warning: unused struct's with self-referential
initialisers
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: dave at treblig dot org
Target Milestone: ---
It would be nice to generate a warning in the following case, which I tripped
over in the Linux kernel:
#include <stdio.h>
struct foo {
struct foo *a;
};
static struct foo f = { &f };
int main()
{
printf("Hello\n");
}
Here 'f' is unused outside of it's initialiser, pointing to itself.
So technically used, but practically not.
In the Linux kernel, this corresponds to it's LIST_HEAD :
(from include/linux/list.h)
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
and I've just gone through and posted patches to remove a handful of
LIST_HEADs, some of which had been unused for many years.
It would be nice if the compiler told people instead.