[libcxx-commits] [libcxx] [libc++] Harden the algorithms against volatile pointers (PR #222813)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Sep 10 18:08:13 PDT 2026
================
@@ -0,0 +1,238 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// Ensure that the algorithms can be instantiated with volatile pointers.
+//
+// A pointer to volatile is a valid Cpp17InputIterator, so algorithms that only require an input iterator are
+// required by the Standard to work with one. It is however not a valid Cpp17ForwardIterator, since its
+// reference type (volatile T&) is neither value_type& nor const value_type&. Supporting the algorithms that
+// require a forward iterator or better is an extension, which we provide on a best-effort basis.
----------------
frederick-vs-ja wrote:
Question only on comments. I'm just uncertain whether we should say comments like these, since I'm sure that some parts of the standard wording consider `volatile T*` as contiguous iterators.
For `ranges` components I submitted [LWG3813](https://cplusplus.github.io/LWG/issue3813).
https://github.com/llvm/llvm-project/pull/222813
More information about the libcxx-commits
mailing list