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
#include <iostream>
#include <memory>
#include <cstdint>
int main() {
int * p = new int (1);
std::declare_reachable(p);
p = (int*)((std::uintptr_t)p ^ UINTPTR_MAX);
p = std::undeclare_reachable((int*)((std::uintptr_t)p ^ UINTPTR_MAX));
std::cout << "p: " << *p << '\n';
delete p;
return 0;
}
The code does not even compile.
demo
user2953119
source
share