Qt-FunctionArgsByValueRef

Warns when you should be passing by value instead of by reference and vice versa

Required inputs: IR

Types with sizeof <= 16 bytes [1] which are trivially copyable [2] and trivially destructible [3] should be passed by value.

Only fix these warnings if you're sure that the value would be passed in a CPU register instead on the stack.

Types with sizeof > 16 bytes or types which are not trivially copyable or not trivially destructible should be passed by reference. A rule of thumb is that if passing by value would trigger a copy constructor destructor call then pass by reference instead.

This check will ignore shared pointers, you are on your own. Most of the times passing shared pointers by const reference is the best thing to do, but occasionally that will lead to crashes if you are in a method that calls something else that makes the shared pointer reference count go down to zero.

Use the message keys to disable one or the other kind of violations.

This rule is based on clazy rules function-args-by-ref and function-args-by-value.

Possible Messages

Key

Text

Severity

Disabled

pass_by_ref

Missing reference on non trivial type “{}”.

None

False

pass_by_value

Pass small and trivially copyable type “{}” by value

None

False

Options

classes_to_ignore

classes_to_ignore

Type: list[bauhaus.analysis.config.QualifiedName]

Default: ['QGenericReturnArgument', 'QtMetaTypePrivate::QSequentialIterableImpl', 'QtMetaTypePrivate::QAssociativeIterableImpl', 'QVariantComparisonHelper', 'QHashDummyValue', 'QCharRef', 'QString::Null', 'std::shared_ptr', 'va_list', 'QSharedPointer', 'boost::shared_ptr', 'QChar', 'QMetaSequence', 'QMetaAssociation', 'QLatin1StringView', 'QMap::iterator', 'QMap::const_iterator']

Classes that should not be considered.
 

functions_to_ignore

functions_to_ignore : list[bauhaus.analysis.config.QualifiedName] = []

Functions that should not be considered.
 

level

level : int = 2

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