https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118074
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Looks like a bad interaction with NRV for the trunk. For 14 and before we get: operator delete (_4); D.12501 = MEM[(struct A &)_4 + 16]; That is even true at -O0: Program returned: 1 ================================================================= ==1==ERROR: AddressSanitizer: heap-use-after-free on address 0x504000000020 at pc 0x000000401466 bp 0x7fffa8da9120 sp 0x7fffa8da9118 READ of size 4 at 0x504000000020 thread T0 #0 0x401465 in func() (/app/output.s+0x401465) (BuildId: fa1e65f64e07304f23fb285cba050c7c7c09d52a) #1 0x4019f1 in main (/app/output.s+0x4019f1) (BuildId: fa1e65f64e07304f23fb285cba050c7c7c09d52a) #2 0x761989e29d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e) #3 0x761989e29e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e) #4 0x4011b4 in _start (/app/output.s+0x4011b4) (BuildId: fa1e65f64e07304f23fb285cba050c7c7c09d52a) 0x504000000020 is located 16 bytes inside of 48-byte region [0x504000000010,0x504000000040) freed by thread T0 here: >The following code gives the expected result using MSVC Is there a way to check to make sure you are not using the value after deconstruction for MSVC too. I am suspecting this is just undefined code.