From 11f334121fd0d13830fefdf08041183da2d30ef3 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Thu, 8 Aug 2024 11:04:47 -0700 Subject: [PATCH] [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 Auto-Submit: Peter Kasting --- include/openssl/span.h | 22 ++++++++++++++++++++++ pki/input.h | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/openssl/span.h b/include/openssl/span.h index 4f11559e7..a6cd5b7a1 100644 --- a/include/openssl/span.h +++ b/include/openssl/span.h @@ -30,6 +30,28 @@ extern "C++" { #include #endif +#if defined(__has_include) +#if __has_include() +#include +#endif +#endif + +#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L +#include +BSSL_NAMESPACE_BEGIN +template +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 +inline constexpr bool std::ranges::enable_view> = true; +template +inline constexpr bool std::ranges::enable_borrowed_range> = true; +#endif + BSSL_NAMESPACE_BEGIN template diff --git a/pki/input.h b/pki/input.h index 6ed79d9e0..15bdbd62e 100644 --- a/pki/input.h +++ b/pki/input.h @@ -14,6 +14,28 @@ #include #include +#if defined(__has_include) +#if __has_include() +#include +#endif +#endif + +#if defined(__cpp_lib_ranges) && __cpp_lib_ranges >= 201911L +#include +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 = true; +template <> +inline constexpr bool std::ranges::enable_borrowed_range = + true; +#endif + namespace bssl::der { // An opaque class that represents a fixed buffer of data of a fixed length,