summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc')
-rw-r--r--libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc
new file mode 100644
index 00000000000..90d11198578
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/creation/constexpr.cc
@@ -0,0 +1,34 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+constexpr bool
+test_creation_single()
+{
+ std::unique_ptr<int> p = std::make_unique<int>(1);
+ VERIFY( *p == 1 );
+ p = std::make_unique_for_overwrite<int>();
+ *p = 2;
+ VERIFY( *p == 2 );
+
+ return true;
+}
+static_assert( test_creation_single() );
+
+constexpr bool
+test_creation_array()
+{
+ std::unique_ptr<int[]> a = std::make_unique<int[]>(2);
+ VERIFY( a[0] == 0 );
+ VERIFY( a[1] == 0 );
+ a = std::make_unique_for_overwrite<int[]>(2);
+ a[0] = 1;
+ a[1] = 2;
+ VERIFY( a[0] == 1 );
+ VERIFY( a[1] == 2 );
+
+ return true;
+}
+static_assert( test_creation_array() );