diff options
Diffstat (limited to 'libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/constexpr.cc')
-rw-r--r-- | libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/constexpr.cc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/constexpr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/constexpr.cc new file mode 100644 index 00000000000..81908fdc081 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/constexpr.cc @@ -0,0 +1,68 @@ +// { dg-options "-std=gnu++23" } +// { dg-do compile { target c++23 } } + +#include <memory> +#include <testsuite_hooks.h> + +constexpr bool +test_release() +{ + std::unique_ptr<int> p1; + int* r = p1.release(); + VERIFY( !r ); + VERIFY( !p1 ); + + std::unique_ptr<int> p2(new int(2)); + r = p2.release(); + VERIFY( r ); + VERIFY( !p2 ); + delete r; + + std::unique_ptr<int[]> a1; + r = a1.release(); + VERIFY( !r ); + VERIFY( !a1 ); + + std::unique_ptr<int[]> a2(new int[2]{}); + r = a2.release(); + VERIFY( r ); + VERIFY( !a2 ); + delete[] r; + + return true; +} +static_assert( test_release() ); + +constexpr bool +test_reset() +{ + std::unique_ptr<int> p1; + p1.reset(); + VERIFY( !p1 ); + p1.reset(nullptr); + VERIFY( !p1 ); + p1.reset(new int(2)); + VERIFY( *p1 == 2 ); + p1.reset(new int(3)); + VERIFY( *p1 == 3 ); + p1.reset(nullptr); + VERIFY( !p1 ); + + std::unique_ptr<int[]> a1; + a1.reset(); + VERIFY( !a1 ); + a1.reset(nullptr); + VERIFY( !a1 ); + a1.reset(new int[]{2,3}); + VERIFY( a1[0] == 2 ); + a1.reset(new int[]{4,5,6}); + VERIFY( a1[1] == 5 ); + a1.reset(nullptr); + VERIFY( !a1 ); + + std::unique_ptr<const int[]> a2; + a2.reset(new int[2]{}); + + return true; +} +static_assert( test_reset() ); |