[Bug rtl-optimization/89303] [8 Regression] memory leak with shared_ptr and enable_shared_from_this

adl at gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Feb 12 15:22:00 GMT 2019


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

--- Comment #6 from Alexandre Duret-Lutz <adl at gnu dot org> ---
I mentioned in my first comment that I had also cases that threw bad_weak_ptr.
I've been able to reproduce those as follows:

% cat badwptr.cc
#include <memory>

class blob final: public std::enable_shared_from_this<blob>
{
};

int main()
{
  std::shared_ptr<blob> tg = std::make_shared<blob>();
  return tg->shared_from_this().use_count();
}

% g++ -g -O badwptr.cc
% ./a.out
terminate called after throwing an instance of 'std::bad_weak_ptr'
  what():  bad_weak_ptr

When compiled with -O2 or -O0, the program exits with $?=2 as expected.


More information about the Gcc-bugs mailing list