Unnecessary implementation of a special member function
Implementing special member functions hinders code optimization when implicit versions are equivalent
Since R2023a
Description
Polyspace® reports this defect if you implement a special member function in your class with the same functionalities as the implicit version of the function. The implicit special member functions typically have these properties:
The implicit default constructor has an empty body, an empty parameter list, and an empty initializer list.
The implicit destructor has an empty body.
The implicit copy constructor copies the base classes and nonstatic data members by using an initializer list. The implicit move constructor moves the base classes and nonstatic data members using an initializer list. The implicit copy and move constructors do not create deep copies and do not move the data associated with a raw pointer.
The implicit copy and move assignment operators use base and member-wise assignments.
For details about how implicitly defined special member functions behave, see:
Risk
Compilers optimize your code by turning implicit special member functions into trivial functions, which are faster to execute. This optimization does not take place if you implement a special member function in your code. Implementing a special member function that you can omit or declare as =default
results in slower code.
Unnecessary implementation of a special member function makes your code more complex, hinders optimization, and makes the code harder to read and maintain.
Fix
To fix this defect, take one of these actions:
Omit the implementation of the flagged special member function.
Declare the special member function as
=default
.
Performance improvements might vary based on the compiler, library implementation, and environment that you are using.
Examples
Result Information
Group: Performance |
Language: C++ (C++11 or later) |
Default: Off |
Command-Line Syntax:
UNNECESSARY_IMPL_OF_SPECIAL_MEMBER_FUNCTION |
Impact: Low |
Version History
Introduced in R2023a
See Also
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)