function

std::get_pointer_safety

<memory>
pointer_safety get_pointer_safety() noexcept;
Get pointer safety
Returns the pointer safety setting used by the implementation, as a value of type pointer_safety, which can take any of the following values:

valuedescription
relaxedThe validity of a pointer value does not depend on whether it is a safely-derived pointer value.
preferredThe 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.
strictA 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.

Parameters

none

Return value

The pointer safety setting of the compiler.
pointer_safety is an enum class type defined in <memory>.

Example

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;
}


Possible output:
Pointer safety: relaxed

See also