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.
- [1] https://www.macieira.org/blog/2012/02/the-value-of-passing-by-value/
- [2] https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable
- [3] https://en.cppreference.com/w/cpp/types/is_destructible
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¶
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
classes_to_ignore¶
classes_to_ignore
Classes that should not be considered.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']
functions_to_ignore¶
functions_to_ignore : list[bauhaus.analysis.config.QualifiedName] = []
level¶
level : int = 2