Qt-TemporaryIterator¶
Do not use functions returning iterators on a temporary container
Required inputs: IR
Example
// temporary list returned by function
QList<type> getList()
{
QList<type> list;
... add some items to list ...
return list;
}
// Will cause a crash if iterated using:
for (QList<type>::iterator it = getList().begin(); it != getList().end(); ++it)
{
...
}
because the end iterator was returned from a different container object than the begin iterator.
This rule is based on clazy rule temporary-iterator
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
temporary_iterator |
Don’t call {class_name}::{member_name}() on temporary |
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
ignored_functions¶
ignored_functions : set[str] = {'QHash::operator[]', 'QMap::operator[]', 'QSet::operator[]', 'QVariant::toList'}
level¶
level : int = 0
methods_by_type¶
methods_by_type
For each container type considered by this rule, the list of member functions that must not be called.Type: dict[str, set[str]]
Default:
{ 'QHash': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'constFind', 'end', 'find', 'insert', 'insertMulti'}, 'QLinkedList': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'end'}, 'QList': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'end'}, 'QMap': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'constFind', 'end', 'equal_range', 'find', 'lowerBound', 'upperBound'}, 'QMultiHash': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'constFind', 'end', 'find', 'insert', 'insertMulti'}, 'QMultiMap': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'constFind', 'end', 'equal_range', 'find', 'lowerBound', 'upperBound'}, 'QQueue': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'end'}, 'QSet': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'constFind', 'end', 'find'}, 'QStack': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'end', 'insert'}, 'QVector': {'begin', 'cbegin', 'cend', 'constBegin', 'constEnd', 'end', 'insert'}, 'std::vector': {'begin', 'cbegin', 'cend', 'end'} }