Base class assignment operator not called
Copy assignment operator does not call copy assignment operators of base subobjects
Description
This defect occurs when a derived class copy assignment operator does not call the copy assignment operator of its base class.
Risk
If this defect occurs, unless you are initializing the base class data members explicitly in the derived class assignment operator, the operator initializes the members implicitly by using the default constructor of the base class. Therefore, it is possible that the base class data members do not get assigned the right values.
If users of your class expect your assignment operator to perform a complete assignment between two objects, they can face unintended consequences.
Fix
Call the base class copy assignment operator from the derived class copy assignment operator.
Even if the base class data members are not private
,
and you explicitly initialize the base class data members in the derived
class copy assignment operator, replace this explicit initialization
with a call to the base class copy assignment operator. Otherwise,
determine why you retain the explicit initialization.
Examples
Result Information
Group: Object oriented |
Language: C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax: MISSING_BASE_ASSIGN_OP_CALL |
Impact: High |
Version History
Introduced in R2015b
See Also
Find defects (-checkers)
| Copy constructor not called in initialization list
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)