https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86296
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Alexis Wilke from comment #3) > However, as an FYI, I tried the -fsanitize=address and the > -D_GLIBCXX_ASSERTIONS command line options as shown in your examples and did > not get any errors reported in my environment. So as much as these look like > useful options, they don't seem to be activated as is. I don't know how _GLIBCXX_ASSERTIONS can possibly not work, are you sure you spelled it correctly? That assertion is definitely present in GCC 7.3's unique_ptr and it will abort with and without optimization: tmp$ ~/gcc/7.3.0/bin/g++ -D_GLIBCXX_ASSERTIONS b.cpp tmp$ ./a.out default initialization: safe_fd = /home/jwakely/gcc/7.3.0/include/c++/7.3.0/bits/unique_ptr.h:322: typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp, _Dp>::operator*() const [with _Tp = int; _Dp = raii_generic_deleter<int, -1, int (*)(int), close>; typename std::add_lvalue_reference<_Tp>::type = int&]: Assertion 'get() != pointer()' failed. Aborted (core dumped) tmp$ ~/gcc/7.3.0/bin/g++ -D_GLIBCXX_ASSERTIONS b.cpp -O3 tmp$ ./a.out default initialization: safe_fd = /home/jwakely/gcc/7.3.0/include/c++/7.3.0/bits/unique_ptr.h:322: typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp, _Dp>::operator*() const [with _Tp = int; _Dp = raii_generic_deleter<int, -1, int (*)(int), close>; typename std::add_lvalue_reference<_Tp>::type = int&]: Assertion 'get() != pointer()' failed. Aborted (core dumped) For -fsanitize=address it only detects the stack-use-after-scope error when optimized. Or you can set ASAN_OPTIONS=detect_stack_use_after_return=1 in the environment for ASan to detect it: tmp$ ~/gcc/7.3.0/bin/g++ -fsanitize=address b.cpp tmp$ ./a.out default initialization: safe_fd = -1 fd = 3 safe_fd after the reset(3) = 3 second close returned -1 (errno = 9) tmp$ ASAN_OPTIONS=detect_stack_use_after_return=1 ./a.out ================================================================= ==18323==ERROR: AddressSanitizer: stack-use-after-return on address 0x7fdf4f200020 at pc 0x000000401003 bp 0x7ffe9cbdb500 sp 0x7ffe9cbdb4f0 READ of size 4 at 0x7fdf4f200020 thread T0 #0 0x401002 in main (/tmp/a.out+0x401002) #1 0x7fdf52b77f29 in __libc_start_main (/lib64/libc.so.6+0x20f29) #2 0x400e49 in _start (/tmp/a.out+0x400e49) Or optimized: tmp$ g++ -fsanitize=address b.cpp -O1 tmp$ ./a.out ================================================================= ==18681==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe1a9d8120 at pc 0x000000400e68 bp 0x7ffe1a9d8070 sp 0x7ffe1a9d8060 READ of size 4 at 0x7ffe1a9d8120 thread T0 #0 0x400e67 in main (/tmp/a.out+0x400e67) #1 0x7f27d4b04f29 in __libc_start_main (/lib64/libc.so.6+0x20f29) #2 0x400c19 in _start (/tmp/a.out+0x400c19) > I even tried to run the code in gdb in case some debug would react there I'm not sure what you mean, but there's nothing that reacts to being debugged. It would not be helpful if debugging the program in gdb changed its behaviour.