| 1 |
// { dg-do compile { target c++23 } } |
| 2 |
|
| 3 |
#include <memory> |
| 4 |
#include <testsuite_hooks.h> |
| 5 |
|
| 6 |
std::unique_ptr<int> intptr; |
| 7 |
|
| 8 |
void |
| 9 |
val_inout(void** p) |
| 10 |
{ |
| 11 |
// The smart pointer should have been released by the inout_ptr_t constructor |
| 12 |
VERIFY( intptr == nullptr ); |
| 13 |
// The initial value of the pointer should be non-null. |
| 14 |
VERIFY( *(int*)*p == 5678 ); |
| 15 |
// Although the implementation is allowed to access the unique_ptr's |
| 16 |
// pointer directly, it can't do that here because the unique_ptr stores |
| 17 |
// an int* and we are reading from and writing to a void*. |
| 18 |
VERIFY( intptr.get() != *p ); |
| 19 |
|
| 20 |
// Return a heap-allocated int in *p. |
| 21 |
*p = (void*) new int(999); |
| 22 |
} |
| 23 |
|
| 24 |
void |
| 25 |
test_inout_ptr_void() |
| 26 |
{ |
| 27 |
intptr.reset(new int(5678)); |
| 28 |
val_inout(std::inout_ptr<void*>(intptr)); |
| 29 |
VERIFY( *intptr == 999 ); |
| 30 |
} |
| 31 |
|
| 32 |
int main() |
| 33 |
{ |
| 34 |
test_inout_ptr_void(); |
| 35 |
} |