AutosarC++17_03-A23.0.1ΒΆ
An iterator shall not be implicitly converted to const_iterator
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
The Standard Template Library introduced methods for returning const iterators to containers. Making a call to these methods and immediately assigning the value they return to a const_iterator, removes implicit conversions.
Example
//% $Id: A23-0-1.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
#include <vector>
void fn1(std::vector<std::int32_t> &v) noexcept {
for (std::vector<std::int32_t>::const_iterator iter{v.cbegin()},
end{v.cend()};
iter != end; ++iter) // Compliant
{
// ...
}
}
void fn2(std::vector<std::int32_t> &v) noexcept {
for (auto iter{v.cbegin()}, end{v.cend()}; iter != end; ++iter) // Compliant
{
// ...
}
}
void fn3(std::vector<std::int32_t> &v) noexcept {
for (std::vector<std::int32_t>::const_iterator iter{v.begin()}, end{v.end()};
iter != end; ++iter) // Non-compliant
{
// ...
}
}
See Also
- HIC++ v4.0 [8]: 17.4.1 Use const container calls when result is immediately converted to a const iterator.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
implicit_const_iterator |
An iterator shall not be implicitly converted to const_iterator. |
None |
False |
Options
This rule shares the following common options: confidence, 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
This rule has no individual options.