[libc++] Add minor test for polymorphic_allocator.construct with mixed argument pair
authorLouis Dionne <ldionne.2@gmail.com>
Wed, 29 Mar 2023 21:01:18 +0000 (17:01 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Wed, 29 Mar 2023 21:02:26 +0000 (17:02 -0400)
libcxx/test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp

index 4677bf0..75bfe6f 100644 (file)
 
 int constructed = 0;
 
+template <int>
 struct default_constructible {
   default_constructible() : x(42) { ++constructed; }
   int x = 0;
 };
 
 int main(int, char**) {
-  // pair<default_constructible, default_constructible> as T()
+  // pair<default_constructible, default_constructible>
   {
-    typedef default_constructible T;
+    typedef default_constructible<0> T;
     typedef std::pair<T, T> P;
     typedef std::pmr::polymorphic_allocator<void> A;
     alignas(P) char buffer[sizeof(P)];
@@ -45,5 +46,20 @@ int main(int, char**) {
     assert(ptr->second.x == 42);
   }
 
+  // pair<default_constructible<0>, default_constructible<1>>
+  {
+    typedef default_constructible<0> T;
+    typedef default_constructible<1> U;
+    typedef std::pair<T, U> P;
+    typedef std::pmr::polymorphic_allocator<void> A;
+    alignas(P) char buffer[sizeof(P)];
+    P* ptr = reinterpret_cast<P*>(buffer);
+    A a;
+    a.construct(ptr);
+    assert(constructed == 2);
+    assert(ptr->first.x == 42);
+    assert(ptr->second.x == 42);
+  }
+
   return 0;
 }