pointer_safety get_pointer_safety() noexcept;
| value | description |
|---|---|
| relaxed | The validity of a pointer value does not depend on whether it is a safely-derived pointer value. |
| preferred | The validity of a pointer value does not depend on whether it is a safely-derived pointer value. A leak detector may be running so that the program can avoid spurious leak reports. |
| strict | A pointer value that is not a safely-derived pointer value is an invalid pointer value unless the referenced complete object is of dynamic storage duration and has previously been declared reachable. A garbage collector may be running so that non-traceable object are automatically deleted. |
reinterpret_cast), including to and from other pointer types or integral types (at least as large as intptr_t), or from sequences of characters with the same size and alignment.1
2
3
4
5
6
7
8
9
10
11
12
13
14
// get_pointer_safety example
#include <iostream>
#include <memory>
int main() {
std::cout << "Pointer safety: ";
switch (std::get_pointer_safety()) {
case std::pointer_safety::relaxed: std::cout << "relaxed"; break;
case std::pointer_safety::preferred: std::cout << "preferred"; break;
case std::pointer_safety::strict: std::cout << "strict"; break;
}
std::cout << '\n';
return 0;
}
Pointer safety: relaxed