GeneralPurpose-PureVirtualCallΒΆ
No pure virtual member calls from within its constructor or destructor
Required inputs: IR
Bad code (pure virtual call in constructor):
class Base {
public:
Base() {
Setup(); // ERROR: indirect pure virtual call
}
virtual void Setup() = 0;
};
class Derived : public Base {
public:
void Setup() override { }
};
Bad code (pure virtual call in destructor):
class Base {
public:
virtual ~Base() {
Cleanup(); // ERROR: pure virtual call in destructor
}
virtual void Cleanup() = 0;
};
Good code (using non-virtual initialization):
class Base {
protected:
void CommonSetup() {
// Non-virtual initialization in base
}
public:
Base() {
CommonSetup(); // OK: non-virtual
}
virtual void Setup() = 0;
};
Good code (move initialization to derived):
class Base {
public:
virtual ~Base() { }
};
class Derived : public Base {
public:
Derived() {
Setup(); // OK: Setup is virtual and overridden
}
void Setup() { }
};
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
indirect_pure_virtual_call |
Pure virtual call (indirectly) called by constructor/destructor. |
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.