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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2018-07-03 00:00:00         |2021-5-13

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's not calling the wrong constructor, GCC is just making a trivial copy of
the object (without using any constructor) for the second operand of the ?:
expression. That is never constructed using a constructor, but it is destroyed,
which causes the double free.

;; Function main (main, funcdef_no=14, decl_uid=2419, cgraph_uid=15,
symbol_order=14) (executed once)

int main ()
{
  struct A D.2421;
  struct A D.2423;
  void * _8;

  <bb 2> [local count: 1073741824]:
  D.2421 ={v} {CLOBBER};
  _8 = operator new (4);
  MEM[(int *)_8] = 42;
  D.2421.a = _8;
  __builtin_printf ("C %p\n", &D.2421);
  D.2423 = D.2421;
  A::~A (&D.2423);
  D.2423 ={v} {CLOBBER};
  A::~A (&D.2421);
  D.2421 ={v} {CLOBBER};
  return 0;

}

Reply via email to