[libcxx-commits] [libcxx] [libc++] Harden the algorithms against volatile pointers (PR #222813)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 15 13:03:56 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.
----------------
ldionne wrote:

Let me know if the reworded comment is what you had in mind!

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


More information about the libcxx-commits mailing list