Qt-RuleOfThree

Implements the rule of three

Required inputs: IR

This is the rule of three with the following exceptions to reduce the amount of warnings. These cases will not emit warnings:
  • the class has a QSharedDataPointer member
  • the class inherits from QSharedData
  • if only the destructor is implemented and it is protected
  • the class name ends with "Private"
  • the class was created via the macro Q_GLOBAL_STATIC_INTERNAL
In some cases you are missing methods, in others you have too many methods. You will have to judge what is the correct fix and beware of binary compatibility.

This rule is based on clazy rule rule-of-three

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

allow_defaulted_destructor_only

allow_defaulted_destructor_only : bool = True

Allow classes with a defaulted destructor and no other special member functions.
 

allow_destructor_only

allow_destructor_only : bool = False

Allow all destructors without copy or move constructors
 

allow_empty_destructor

allow_empty_destructor : bool = True

Allow empty destructors without copy or move constructors.
 

allow_missing_destructor

allow_missing_destructor : bool = False

Suppress messages about missing destructors.
 

allow_protected_destructor_only

allow_protected_destructor_only : bool = True

Allow a protected destructor without copy or move constructors
 

ignore_classes_ending_with_string

ignore_classes_ending_with_string : set[str] = {'Private'}

Do not report a class name that ends with one of the given strings.
 

ignore_classes_inheriting_from

ignore_classes_inheriting_from : set[bauhaus.analysis.config.QualifiedName] = {'QSharedData'}

Do not report a class that inherits from one of the given classes.
 

ignore_classes_with_member_type

ignore_classes_with_member_type : set[bauhaus.analysis.config.QualifiedName] = {'QSharedDataPointer'}

Do not report a class that has a member with one of the given types.
 

ignore_macro_expanded_classes

ignore_macro_expanded_classes : set[bauhaus.analysis.config.MacroName] = {'Q_GLOBAL_STATIC_INTERNAL'}

Do not report a class expanded via one of the given macro names.
 

ignore_pod_classes

ignore_pod_classes : bool = True

Whether POD classes should be checked at all.
 

level

level : int = 2

Importance level of the rule as given for clazy. 0 is most desirable, higher values fall off in quality.