diff gcc/testsuite/g++.dg/cpp2a/cond-triv1.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/g++.dg/cpp2a/cond-triv1.C	Thu Feb 13 11:34:05 2020 +0900
@@ -0,0 +1,46 @@
+// Testcase from P0848R0
+// { dg-do compile { target concepts } }
+
+#include <type_traits>
+
+template <typename T>
+class optional
+{
+  struct empty {};
+  union {
+    empty _ = { };
+    T value;
+  };
+  bool engaged = false;
+
+public:
+  constexpr optional() = default;
+
+  constexpr optional(optional const&)
+    requires std::is_trivially_copy_constructible_v<T>
+    = default;
+  constexpr optional(optional const& o)
+    : engaged (o.engaged)
+  {
+    if (engaged)
+      new (&value) T (o.value);
+  }
+
+  ~optional()
+    requires std::is_trivially_destructible_v<T>
+    = default;
+  ~optional()
+  {
+    if (engaged)
+      value.~T();
+  }
+
+  // ...
+};
+
+struct A { A(); A(const A&); ~A(); };
+
+static_assert(std::is_trivially_copy_constructible_v<optional<int>>);
+static_assert(!std::is_trivially_copy_constructible_v<optional<A>>);
+static_assert(std::is_trivially_destructible_v<optional<int>>);
+static_assert(!std::is_trivially_destructible_v<optional<A>>);