Using SoftBench CodeAdvisor
freeing the memory would be an error.
SoftBench CodeAdvisor can detect this sort of logic error. It scans your program, looking for operator= definitions, and makes sure you check for the classA = classA case. If not, it warns you to fix your code.
SoftBench CodeAdvisor rules focus on finding actual or potential defects in your code. Other rules check for maintenance, performance, and future problems or porting issues. These example rules show how to check for potential problems:
If any member of a class is virtual, the destructor should be virtual.
When a class contains a
The problem doesn't actually occur unless a derived class instance with a
Provide an operator= for classes that dynamically allocate memory or declare a copy constructor.
The default operator= simply copies the fields of one instance to another. If the instance contains pointers to memory allocated by new, the default operator= makes two copies of the pointers. When one of the instances is deleted, it deallocates the memory using delete, and the other instance contains a dangling pointer.
Refer to SoftBench Online Help for a complete list of rules shipped with SoftBench CodeAdvisor.
146 | Chapter 6 |