binutils-gdb/gdb/common
Pedro Alves c053b65441 Initialize gdb::optional empty payload to quiet false -Wmaybe-uninitialized warnings
Commit ecfb656c37 ("dwarf2read.c: Make dir_index and
file_name_index strong typedefs") added a use of gdb::optional that
triggers bogus -Wmaybe-uninitialized warnings:

GCC trunk is complaining like this:

  ../../binutils-gdb/gdb/dwarf2read.c: In function void read_formatted_entries(bfd*, const gdb_byte**, line_header*, const comp_unit_head*, void (*)(line_header*, const char*, dir_index, unsigned int, unsigned int)):
  ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: fe.file_entry::length may be used uninitialized in this function [-Werror=maybe-uninitialized]
	 callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length);
								   ^
  ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: *((void*)& fe +8) may be used uninitialized in this function [-Werror=maybe-uninitialized]
  ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: fe.file_entry::mod_time may be used uninitialized in this function [-Werror=maybe-uninitialized]
  ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: fe.file_entry::name may be used uninitialized in this function [-Werror=maybe-uninitialized]

While some older GCCs are complaining like this:

  ../../binutils-gdb/gdb/dwarf2read.c: In function void read_formatted_entries(bfd*, const gdb_byte**, line_header*, const comp_unit_head*, void (*)(line_header*, const char*, dir_index, unsigned int, unsigned int)):
  ../../binutils-gdb/gdb/dwarf2read.c:17779:65: error: uint may be used uninitialized in this function [-Werror=maybe-uninitialized]
	 callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length);

Looking around the web, I see that boost's optional implementation
triggers this kind of issue often too.  See:

  http://www.boost.org/doc/libs/1_63_0/libs/optional/doc/html/boost_optional/tutorial/gotchas/false_positive_with__wmaybe_uninitialized.html

I noticed that replacing the gdb::optional uses with real C++17
std::optional uses against GCC 7/trunk makes the warnings go away.
Looking at the implementation, AFAICS, libstdc++ always initializes
its "empty" union payload member (_M_empty, which is defined as an
empty class, like ours).  I.e., all payload types have this ctor:

    struct _Optional_payload.....
    {
      constexpr _Optional_payload()
	: _M_empty() {}

The constexpr makes a diference too.  Without it, GCC7 still warns.

So I'm applying the same treatment to our gdb::optional.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

	* common/gdb_optional.h (optional::optional): Make constexpr and
	initialize m_dummy.
2017-04-05 01:28:06 +01:00
..
agent.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
agent.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ax.def update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
break-common.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
btrace-common.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
btrace-common.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
buffer.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
buffer.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cleanups.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
cleanups.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-debug.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-debug.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-defs.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-exceptions.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-exceptions.h DWARF-5: call sites 2017-02-20 21:00:55 +01:00
common-regcache.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-regcache.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-types.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-utils.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common-utils.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common.host update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
common.m4 update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
create-version.sh update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
enum-flags.h Default initialize enum flags to 0 2017-02-21 11:48:49 -05:00
environ.c Share gdb/environ.[ch] with gdbserver 2017-03-07 15:39:35 -05:00
environ.h Share gdb/environ.[ch] with gdbserver 2017-03-07 15:39:35 -05:00
errors.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
errors.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fileio.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
fileio.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
filestuff.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
filestuff.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
format.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
format.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
function-view.h Introduce gdb::function_view 2017-02-23 16:14:08 +00:00
gdb_assert.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_locale.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_optional.h Initialize gdb::optional empty payload to quiet false -Wmaybe-uninitialized warnings 2017-04-05 01:28:06 +01:00
gdb_ref_ptr.h Use class to manage BFD reference counts 2017-01-10 19:14:10 -07:00
gdb_setjmp.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_signals.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_sys_time.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_unique_ptr.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_unlinker.h gdb: Fix ATTRIBUTE_NONNULL usage 2017-03-08 15:52:16 +00:00
gdb_vecs.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_vecs.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
gdb_wait.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
host-defs.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
mingw-strerror.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
new-op.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
offset-type.h Make sect_offset and cu_offset strong typedefs instead of structs 2017-04-04 20:03:26 +01:00
posix-strerror.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
preprocessor.h Make sect_offset and cu_offset strong typedefs instead of structs 2017-04-04 20:03:26 +01:00
print-utils.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
print-utils.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ptid.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ptid.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
queue.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
rsp-low.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
rsp-low.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
run-time-clock.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
run-time-clock.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
scoped_restore.h gdb: make_scoped_restore and types convertible to T 2017-01-31 17:56:35 +00:00
signals-state-save-restore.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signals-state-save-restore.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
signals.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
symbol.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
traits.h Make sect_offset and cu_offset strong typedefs instead of structs 2017-04-04 20:03:26 +01:00
underlying.h dwarf2read.c: Make dir_index and file_name_index strong typedefs 2017-04-04 20:03:25 +01:00
valid-expr.h Make sect_offset and cu_offset strong typedefs instead of structs 2017-04-04 20:03:26 +01:00
vec.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
vec.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
version.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
x86-xstate.h Add support for Intel PKRU register to GDB and GDBserver. 2017-02-17 11:44:48 +01:00
xml-utils.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
xml-utils.h update copyright year range in GDB files 2017-01-01 10:52:34 +04:00