[libcxx-commits] [libcxx] [libc++] Fix strict aliasing violation for `deque::const_iterator` (PR #136067)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 9 04:19:40 PDT 2026


================
@@ -283,7 +304,18 @@ template <class _ValueType,
 #  endif
           >
 class __deque_iterator {
-  typedef _MapPointer __map_iterator;
+  using __map_iterator _LIBCPP_NODEBUG = __get_deque_map_iterator<_ValueType, _MapPointer>;
----------------
frederick-vs-ja wrote:

> Actually, I don't think there is a reason to ever not have that `const`, since the iterator should never modify the map, so I think we should be able to rebind to `const _Pointer` unconditionally.

> What I mean by "build up the type" is constructing it from the other parts we have instead of decomposing the `_MapPointer` and trying to stitch it back together.

Hmm, I see, thanks!

IIUC both `iterator` and `const_iterator` should store `FancyPtr<const FancyPtr<T>>` (or `T* const*` if not fancy) as `__m_iter_`. Given `_ValueType` is the element type of `deque` and should be always cv-unqualified, `__map_iterator` should be `__rebind_pointer_t<const __rebind_pointer_t<_Pointer, _ValueType> >`.

This way will generalize potential ABI breakage to `deque::iterator` for some weirdly designed fancy pointers. But I think it would be worthwhile.

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


More information about the libcxx-commits mailing list