Reputation: 3877
The C++ Standard Library - A Tutorial and Reference, 2nd Edition refers to safe versions of the STL which support various utilities such as runtime bounds checking for operator []
and other operators. For example, on p247:
Thus, it is a good idea to use a "safe" STL, at least during software development. A first version of a safe STL was introduced by Cary Horstmann (see [SafeSTL]). Another example is the "STLport", which is available for free for almost any platform at [STLPort]. In addition, library vendors now provide flags to enable a "safer" mode, which especially should be enabled during development.
Both suggested packages seem relatively dated (last developed in 2008) and don't include more recent C++11/14 features. Are there any more recent reputable implementations available for/with some of the major compilers on Linux (gcc
or clang
) or as standalone libraries?
Upvotes: 1
Views: 398
Reputation: 63134
libstdc++ has a debug mode, which can be enabled by defining _GLIBCXX_DEBUG
when compiling.
The libstdc++ debug mode performs checking for many areas of the C++ standard, but the focus is on checking interactions among standard iterators, containers, and algorithms, including:
Safe iterators: Iterators keep track of the container whose elements they reference, so errors such as incrementing a past-the-end iterator or dereferencing an iterator that points to a container that has been destructed are diagnosed immediately.
Algorithm preconditions: Algorithms attempt to validate their input parameters to detect errors as early as possible. For instance, the
set_intersection
algorithm requires that its iterator parametersfirst1
andlast1
form a valid iterator range, and that the sequence[first1, last1)
is sorted according to the same predicate that was passed to set_intersection; the libstdc++ debug mode will detect an error if the sequence is not sorted or was sorted by a different predicate.
Bounds checking in operator[]
is included.
Upvotes: 7