GeneralPurpose-RuleOfThree¶
Certain special functions must always be declared together (e.g. copy constructor and copy assignment operator)
Required inputs: IR
In most cases, you should follow the Rule of Zero: resource management should be encapsulated in classes
that do nothing except managing a single resource.
Often, the classes std::unique_ptr or std::shared_ptr can be used for this purpose
(with custom deleters).
This frees up all other classes from the task of resource management: those classes should not define any special member functions,
and rely on the compiler-generated default implementations instead.
When implementing a class that manages resources, follow the Rule of Three or Rule of Five:
- Explicitly declare the copy constructor, copy assignment operator and destructor (copyable class without move semantics); or
- Explicitly declare the move constructor, move assignment operator and destructor (non-copyable class with move semantics); or
- Explicitly declare the copy constructor, copy assignment operator, move constructor, move assignment operator and destructor (copyable class with move semantics)
Exception
A destructor with an empty body (or one defined as 'References
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
missing_constructor_and_asgn |
Class with destructor should also declare a copy or move constructor and assignment operator. |
None |
False |
missing_copy_asgn |
Class with copy constructor is missing copy assignment operator. |
None |
False |
missing_copy_constructor |
Class with copy assignment operator is missing copy constructor. |
None |
False |
missing_destructor |
Class with copy or move constructors or assignment operators should also declare a destructor. |
None |
False |
missing_move_asgn |
Class with move constructor is missing move assignment operator. |
None |
False |
missing_move_constructor |
Class with move assignment operator is missing move constructor. |
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
allow_defaulted_destructor_only¶
allow_defaulted_destructor_only : bool = True
allow_destructor_only¶
allow_destructor_only : bool = False
allow_empty_destructor¶
allow_empty_destructor : bool = True
allow_missing_destructor¶
allow_missing_destructor : bool = False
allow_protected_destructor_only¶
allow_protected_destructor_only : bool = False
ignore_classes_ending_with_string¶
ignore_classes_ending_with_string : set[str] = set()
ignore_classes_inheriting_from¶
ignore_classes_inheriting_from : set[bauhaus.analysis.config.QualifiedName] = set()
ignore_classes_with_member_type¶
ignore_classes_with_member_type : set[bauhaus.analysis.config.QualifiedName] = set()
ignore_macro_expanded_classes¶
ignore_macro_expanded_classes : set[bauhaus.analysis.config.MacroName] = set()
ignore_pod_classes¶
ignore_pod_classes : bool = True