[gdb/tui] Fix Wmaybe-uninitialized warning in tui-winsource.c
authorTom de Vries <tdevries@suse.de>
Thu, 23 Jul 2020 11:45:46 +0000 (13:45 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 23 Jul 2020 11:45:46 +0000 (13:45 +0200)
When compiling with CFLAGS/CXXFLAGS="-O0 -g -Wall" and using g++ 11.0.0, we
run into:
...
src/gdb/tui/tui-winsource.c: In function \
  'void tui_update_all_breakpoint_info(breakpoint*)':
src/gdb/tui/tui-winsource.c:427:58: warning: '<unknown>' may be used \
  uninitialized [-Wmaybe-uninitialized]
  427 |   for (tui_source_window_base *win : tui_source_windows ())
      |                                                          ^
In file included from src/gdb/tui/tui-winsource.c:38:
src/gdb/tui/tui-winsource.h:236:30: note: by argument 1 of type \
  'const tui_source_windows*' to 'tui_source_window_iterator \
  tui_source_windows::begin() const' declared here
  236 |   tui_source_window_iterator begin () const
      |                              ^~~~~
src/gdb/tui/tui-winsource.c:427:58: note: '<anonymous>' declared here
  427 |   for (tui_source_window_base *win : tui_source_windows ())
      |                                                          ^
...

The warning doesn't make sense for an empty struct, PR gcc/96295 has been
filed about that.

For now, work around the warning by defining a default constructor.

Build on x86_64-linux.

gdb/ChangeLog:

2020-07-23  Tom de Vries  <tdevries@suse.de>

PR tui/26282
* tui/tui-winsource.h (struct tui_source_windows::tui_source_windows):
New default constructor.

gdb/ChangeLog
gdb/tui/tui-winsource.h

index c400d234f5fbdff26075f818df54484d194cbee4..37035206f490586c1329bffb6189551929dab780 100644 (file)
@@ -1,3 +1,9 @@
+2020-07-23  Tom de Vries  <tdevries@suse.de>
+
+       PR tui/26282
+       * tui/tui-winsource.h (struct tui_source_windows::tui_source_windows):
+       New default constructor.
+
 2020-07-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * disasm.c (do_mixed_source_and_assembly_deprecated): Don't
index fab1487f637e5a22cdb11e3f7482953fa6aa46e3..ba9c0fd505e09a82b5953313e730c82d29bde8d0 100644 (file)
@@ -233,6 +233,11 @@ private:
 
 struct tui_source_windows
 {
+  /* Work around Wmaybe-uninitalized warning with g++ 11.0.0, see also
+     PR gcc/96295.  Note that "tui_source_windows () = default" doesn't work
+     around the warning.  */
+  tui_source_windows () {}
+
   tui_source_window_iterator begin () const
   {
     return tui_source_window_iterator (tui_windows.begin (),