[libcxx-commits] [libcxx] [libc++][hardening] Constrain construction for `__{bounded, wrap}_iter` (PR #115271)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 7 06:36:03 PST 2024


================
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+
+// <iterator>
+
+// __bounded_iter<_Iter>
+// __wrap_iter<_Iter>
+
+// Verify that libc++-wrapped iterators do not permit slicing conversion or construction.
+
+#include <array>
+#include <vector>
+#include <span>
+#include <type_traits>
+
+#include "test_macros.h"
+
+struct Base {};
+struct Derived : Base {};
+
+#ifdef _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
----------------
ldionne wrote:

Instead, I would do something like

```
if constexpr (!std::is_pointer_v<std::array<T, N>::iterator>) {
  // now test
}
```

That way we'll handle wrapped iterators in `std::array`, but also bounded iterators, and anything future.

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


More information about the libcxx-commits mailing list