Archived issue #0025616

Avoid Classes using "new" to allocate Instances but not defining a copy Constructor

Open CASCADEOCCT:Codingclosed7 public notes

Search issues

Description

A copy constructor is highly recommended to avoid surprises when an object is initialized using an object of the same type. If an object manages the allocation and deallocation of an object on the heap (the managing object has a pointer to the object to be created by the class' constructor), only the value of the pointer will be copied. This can lead to two invocations of the destructor for the same object (on the heap), probably resulting in a run-time error.

Steps to reproduce

not applicable

Additional information

The following classes use “new” function without Handles:
- Select3D_PointData
- BSB_T3Bits
- IntPatch_InfoPD
- LDOM_StringElem
- BinomAllocator
- ProjLib_OnSurface
- Standard_MMgrFactory

Objects of these classes must not be copied. It is necessary to add empty copy constructor and assignment operator to protected/private section.

Public activity

7 archived notes

Participants are labeled by their role within this record.

01Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Wed Dec 17 12:37:06 2014 +0300

    0025616: Avoid Classes using "new" to allocate Instances but not defining a copy Constructor
    
    The empty copy constructor, assignemnts operator, default constructors added to the following classes:
02Commenter 2
Branch [archived branch] has been updated by Author.

[revision removed]


Detailed log of new commits:

Author: Author
Date: Fri Dec 26 15:34:13 2014 +0300

    0025616: Avoid Classes using "new" to allocate Instances but not defining a copy Constructor
    
    Useless declaration of default constructor have been deleted.

03Commenter 3
No remarks, please test
04Commenter 2
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
05Commenter 5
Branch [archived branch] has been rebased on the current master
06Commenter 6
Dear Commenter 1,

Branch CR25616 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]

Number of compiler warnings:
occt component:
   Linux: 18 (18 on master)
   Windows: 0 (0 on master)
products component :
   Linux: 11 (11 on master)
   Windows: 1 (1 on master)

Regressions/Differences:
Not detected

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 369216928 / 369132708
Total CPU difference: 50656.09000000034 / 46134.12000000006

Testing on Windows:
Total MEMORY difference: 276574444 / 276918412
Total CPU difference: 39410.21875 / 38326.15625
07Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]

Related records