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

            Bug ID: 83923
           Summary: No destructor called for constructor argument
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mszyszkowski93 at gmail dot com
  Target Milestone: ---

Created attachment 43167
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43167&action=edit
Source files

gcc version 7.2.0 (GCC)
system type: x86_64-pc-linux-gnu 
command line to compile and run:
g++ -Wall -Wextra main.cpp && ./a.out 
and
g++ -Wall -Wextra main2.cpp && ./a.out  
for second version of program.

Binary from main.cpp, in which class is created by following way:
B* b = new B();
creates following output:

Constructor
0

Binary from main2.cpp, in which class is created by following way:
B* b = new B;
creates following output:

Constructor
0
Destructor

So destructor for B's constructor argument (A class) is not called when giving
'()'  when creating B.
Clang in version 5.0.0 produces:

Constructor
0
Destructor

in both cases. Source files included

Reply via email to