Safe or strict pointer security?

I came across concepts relaxed/strict pointer safetyand what exactly the implementation determines whether there was a relaxation of the implementation or strict security of the pointer. My question is about modern implementations: Do clang and g ++ have strict or relaxed pointer security?

I would like to clarify the following about a strict pointer security concept. There is a quote (section 3.7.4.3/4):

Alternatively, the implementation may have strict pointer security, in which case the pointer value refers to an object with dynamic storage duration, which is not a safe pointer value, the pointer value is invalid if the complete object has not been specified previously, is declared reachable (20.7.4 )

This limitation is completely unclear to me. Moreover, I tried to experiment with the concept example cplusplus.com

// declare_reachable / undeclare_reachable example
#include <iostream>
#include <memory>
#include <cstdint>

int main() {
  int * p = new int (1);    // dynamic object

  std::declare_reachable(p);

  p = (int*)((std::uintptr_t)p ^ UINTPTR_MAX);  // scrambling p

  // dynamic object not reachable by any live safely-derived pointer

  p = std::undeclare_reachable((int*)((std::uintptr_t)p ^ UINTPTR_MAX));
  // p is back again a safely-derived pointer to the dynamic object

  std::cout << "p: " << *p << '\n';
  delete p;

  return 0;
}

The code does not even compile.

demo

+4
source share
2 answers

This stuff allows you to allow garbage collection, although I don’t know of any compilers (at least in the mainstream) that use this.

Allegedly, you can find out if your doing using std::get_pointer_safety, but it looks bad too .

I would just ignore him.

+1
source

From cppference.com C ++ preprocessor

has this predefined macro: STDCPP_STRICT_POINTER_SAFETY (C ++ 11)

1, std:: pointer_safety ( )

, ( 0), /.

0

All Articles