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

            Bug ID: 98406
           Summary: missing -Wmaybe-uninitialized passing a member by
                    reference
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In the test case below, only the first (likely) uninitialized read by f() is
diagnosed.  The other two are not even though all three should be.

$ cat a.c && gcc -O2 -S -Wall a.c
int f (const int*);

struct A { int i; };
struct B { struct A a; int j; };

void g0 (void)
{
  struct B b;
  f (&b.j);        // warning (good)
}

void g1 (void)
{
  struct B b;
  f (0);
  f (&b.j);        // missing warning
}

void g2 (void)
{
  struct B b;
  b.a.i = 0;
  f (&b.a.i); 
  f (&b.j);        // missing warning
}

a.c: In function ‘g0’:
a.c:9:3: warning: ‘b’ may be used uninitialized [-Wmaybe-uninitialized]
    9 |   f (&b.j);        // warning (good)
      |   ^~~~~~~~
a.c:1:5: note: by argument 1 of type ‘const int *’ to ‘f’ declared here
    1 | int f (const int*);
      |     ^
a.c:8:12: note: ‘b’ declared here
    8 |   struct B b;
      |            ^

Reply via email to