Qt-Generic-MissingBaseCopyΒΆ
Do call the base class copy constructor or assignment operator, if you implement a copy constructor or assignment operator in a derived class
Required inputs: IR
Bad code:
class Base {
int i;
};
class Derived : public Base {
public:
Derived(const Derived& other) {} // ERROR: Copy constructor should explicitly call copy constructor of its base classes.
Derived& operator=(const Derived& other) {} // ERROR: Assignment operator should explicitly call assignment operator of its base classes.
};
Good code (explicit calls to base class copy constructor and assignment operator):
class Base {
int i;
};
class Derived : public Base {
public:
Derived(const Derived& other) : Base(other) {} // OK: Copy constructor explicitly calls copy constructor of its base class.
Derived& operator=(const Derived& other) {
if (this != &other) {
Base::operator=(other); // OK: Assignment operator explicitly calls assignment operator of its base class.
// ...
}
return *this;
}
};
Good code (empty base class has trivial copy constructor):
class Base {
public:
virtual void foo() = 0;
};
class Derived : public Base {
public:
Derived(const Derived& other) {} // OK: Base class is empty and copy constructor is trivial, so no explicit call is needed.
void foo() override {}
};
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
missing_assignment_call |
Assignment operator should explicitly call assignment operator of its base classes. |
None |
False |
missing_constructor_call |
Copy constructor should explicitly call copy constructor of its base classes. |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.