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

            Bug ID: 98405
           Summary: missing -Wmaybe-uninitialized passing a member by
                    reference in a ctor initializer list
           Product: gcc
           Version: unknown
            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: ---

As discussed in
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/559258.html, GCC 11
issues -Wmaybe-uninitialized when passing uninitialized variables by reference
to functions that take a const pointer or const reference.  However, it fails
to diagnose the same problem involving members in a C++ constructor.  For
example, in the test case below, only the first instance triggers the warning. 
The other two don't.

$ cat a.C && gcc -O2 -S -Wall a.C

int f (const int*);

struct X {
  int a, b;
};

void g ()
{
  X x;
  x.a = f (&x.b);          // warning (good)
}

struct Y {
 Y ();
 Y (int);
  int a, b;
};

Y::Y (): a (f (&b)) { }    // missing warning
Y::Y (int) { f (&b); }     // missing warning

a.C: In function ‘void g()’:
a.C:10:11: warning: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
   10 |   x.a = f (&x.b);          // warning (good)
      |         ~~^~~~~~
a.C:1:5: note: by argument 1 of type ‘const int*’ to ‘int f(const int*)’
declared here
    1 | int f (const int*);
      |     ^
a.C:9:5: note: ‘x’ declared here
    9 |   X x;
      |     ^

Reply via email to