[Bug c++/79345] passing yet-uninitialized member as argument to base class constructor should warn (-Wunitialized)

palves at redhat dot com gcc-bugzilla@gcc.gnu.org
Thu Feb 2 16:21:00 GMT 2017


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

--- Comment #1 from Pedro Alves <palves at redhat dot com> ---
Note, if we add a use of gdb_disassembler::m_stream somewhere, like:

  gdb_disassembler_test ()
    : gdb_disassembler (verbose == 123 ? &stream_v : &stream_q) // bug here
  {
    if (m_stream != &stream_v)
      abort ();
  }

then g++ 7 warns at -O2:

$ /opt/gcc/bin/g++ -std=gnu++11 -O2 -Wall -Wextra -Wuninitialized gcc-bug.cc -o
gcc-bug
gcc-bug.cc: In function ‘int main()’:
gcc-bug.cc:19:63: warning: ‘di.gdb_disassembler_test::verbose’ is used
uninitialized in this function [-Wuninitialized]
     : gdb_disassembler (verbose == 123 ? &stream_v : &stream_q) // bug here
                                                               ^
gcc-bug.cc:29:25: note: ‘di.gdb_disassembler_test::verbose’ was declared here
   gdb_disassembler_test di;
                         ^~

Unfortunately, the compilation unit that has this but in gdb doesn't have
any use like that, so the bug went unnoticed.

To reiterate, I think the frontend _should_ be able to warn even without seeing
the use of m_stream.  I.e., I don't think this bug is the same category as the
other truckload of bugs about missing -Winitialized opportunities at -O0
related to not running some parts of the optimization pipeline.


More information about the Gcc-bugs mailing list