AutosarC++17_10-A18.1.2ΒΆ

The std::vector<bool> specialization shall not be used

Required inputs: IR

Rationale

The std::vector<bool> specialization does not work with all STL algorithms as expected. In particular operator[] does not return a contiguous sequence of elements as it does for other types.

The C++ Language Standard guarantees that elements of an STL container can be safely concurrently modified, except for an std::vector<bool>.

Note that fixed-size std::array of bools, std::deque<bool> or creating POD wrapper for bool type and using it with std::vector are possible alternatives.

Example
// $Id: A18-1-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
#include <vector>
void Fn() noexcept {
  std::vector<std::uint8_t> v1; // Compliant
  std::vector<bool> v2;         // Non-compliant
}
See Also
  • HIC++ v4.0 [8]: 17.1.1 Do not use std::vector<bool>.

Possible Messages

Key

Text

Severity

Disabled

type_used

The type vector<bool> shall not be used.

None

False

Options