function
<memory>

std::undeclare_no_pointers

void undeclare_no_pointers (char* p, size_t n);
Undeclare memory block as containing no pointers
Undeclares the range of memory described by p and n previously declared as containing no traceable pointer locations by a call to declare_no_pointers.

This function shall be called for all ranges declared with declare_no_pointers before the object containing the range is destroyed.

This does not restore the valitidy of dynamic objects previously invalidated by de the call to declare_no_pointers.

Parameters

p
Pointer to the first byte of the range.
This shall be the same value passed to a previous call to declare_pointers.
n
The length, expressed in bytes, of the range.
This shall be the same value passed to a previous call to declare_pointers.
size_t is an unsigned integral type.

Return value

none

This function throws no exceptions.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// declare_no_pointers / undeclare_no_pointers #include <iostream> #include <memory> int main() { int * foo = new int(1); int * bar = new int(2); std::declare_no_pointers (reinterpret_cast<char*>(&bar),sizeof(int*)); std::cout << "*foo: " << *foo << '\n'; if (std::get_pointer_safety() != std::pointer_safety::strict) std::cout << "*bar: " << *bar << '\n'; // invalid if strict safety std::undeclare_no_pointers (reinterpret_cast<char*>(&bar),sizeof(int*)); delete bar; delete foo; return 0; }

Possible output:
*foo: 1 *bar: 2 


See also