[libcxx-commits] [libcxx] [libc++] ~vector: Don't __clear trivial typed elements (PR #86947)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 2 00:32:04 PDT 2024


================
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <vector>
+#include <cassert>
+
+struct int_alloc
+{
+    typedef int value_type;
+
+    template< class U >
+    struct rebind
+    {
+        typedef int_alloc other;
+    };
+
+    int* allocate(std::size_t n)
+    {
+        return new int[n];
+    }
+    void deallocate(int* p, std::size_t n)
+    {
+        for (std::size_t i = 0; i < n; ++i) {
+            assert(p[i] != 0);
----------------
frederick-vs-ja wrote:

IIUC this is testing UB. Perhaps this test file should be moved to `libcxx/test/libcxx` subdirectory.

https://github.com/llvm/llvm-project/pull/86947


More information about the libcxx-commits mailing list