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

--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> ---
95911 boils down to this:

#include <utility>

struct X { int i = 0; };

X&& f(X&& x) { return std::move(x); }

int main()
{
  X&& x = f(X{});
  return x.i;
}

With recent releases we get a -Wuninitialized warning, which isn't entirely
correct, but at least suggests a problem:

49974.cc: In function 'int main()':
49974.cc:10:12: warning: '<anonymous>.X::i' is used uninitialized
[-Wuninitialized]
   10 |   return x.i;
      |            ^
49974.cc:9:15: note: '<anonymous>' declared here
    9 |   X&& x = f(X{});
      |               ^

(the note is new in GCC 11).

With -fsanitize=address we get a nice stack-use-after-scope error:

==3088273==ERROR: AddressSanitizer: stack-use-after-scope on address
0x7fff976ed520 at pc 0x000000401100 bp 0x7fff976ed4f0 sp 0x7fff976ed4e8
READ of size 4 at 0x7fff976ed520 thread T0
    #0 0x4010ff in main /tmp/49974.cc:10
    #1 0x7fd157d181a2 in __libc_start_main ../csu/libc-start.c:308
    #2 0x40116d in _start (/tmp/a.out+0x40116d)

Reply via email to