[jumbo] Mark Span and Input as satisfying view and borrowed_range. These concepts are appropriate for these types, and we also enable them for e.g. base::span. This is necessary for Chromium to annotate more base::span constructors with LIFETIMEBOUND without producing false positive warnings with these types. It only has an effect under C++20 (but should preprocess away to nothing on older C++ versions). Bug: none Change-Id: Ib2b8cba4b7bd2d5028ce27de4fd9c44fca7d5560 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/70068 Reviewed-by: David Benjamin <davidben@google.com> Auto-Submit: Peter Kasting <pkasting@google.com>
diff --git a/include/openssl/span.h b/include/openssl/span.h index 4f11559..a6cd5b7 100644 --- a/include/openssl/span.h +++ b/include/openssl/span.h
@@ -30,6 +30,28 @@ #include <string_view> #endif +#if defined(__has_include) +#if __has_include(<version>) +#include <version> +#endif +#endif + +#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L +#include <ranges> +BSSL_NAMESPACE_BEGIN +template <typename T> +class Span; +BSSL_NAMESPACE_END + +// Mark `Span` as satisfying the `view` and `borrowed_range` concepts. This +// should be done before the definition of `Span`, so that any inlined calls to +// range functionality use the correct specializations. +template <typename T> +inline constexpr bool std::ranges::enable_view<bssl::Span<T>> = true; +template <typename T> +inline constexpr bool std::ranges::enable_borrowed_range<bssl::Span<T>> = true; +#endif + BSSL_NAMESPACE_BEGIN template <typename T>
diff --git a/pki/input.h b/pki/input.h index 6ed79d9..15bdbd6 100644 --- a/pki/input.h +++ b/pki/input.h
@@ -14,6 +14,28 @@ #include <openssl/base.h> #include <openssl/span.h> +#if defined(__has_include) +#if __has_include(<version>) +#include <version> +#endif +#endif + +#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L +#include <ranges> +namespace bssl::der { +class OPENSSL_EXPORT Input; +} + +// Mark `Input` as satisfying the `view` and `borrowed_range` concepts. This +// should be done before the definition of `Input`, so that any inlined calls to +// range functionality use the correct specializations. +template <> +inline constexpr bool std::ranges::enable_view<bssl::der::Input> = true; +template <> +inline constexpr bool std::ranges::enable_borrowed_range<bssl::der::Input> = + true; +#endif + namespace bssl::der { // An opaque class that represents a fixed buffer of data of a fixed length,