Commit 4b4f41e9 by Abseil Team Committed by Copybara-Service

Add ABSL_ATTRIBUTE_LIFETIME_BOUND to absl::Span constructors.

This enables clang to catch more use-after-free bugs.

PiperOrigin-RevId: 692275317
Change-Id: I86c414a90d24d239ed67b3316fe74e1c24f95ed9
parent 9ae4bb80
...@@ -219,12 +219,14 @@ class ABSL_ATTRIBUTE_VIEW Span { ...@@ -219,12 +219,14 @@ class ABSL_ATTRIBUTE_VIEW Span {
static const size_type npos = ~(size_type(0)); static const size_type npos = ~(size_type(0));
constexpr Span() noexcept : Span(nullptr, 0) {} constexpr Span() noexcept : Span(nullptr, 0) {}
constexpr Span(pointer array, size_type length) noexcept constexpr Span(pointer array ABSL_ATTRIBUTE_LIFETIME_BOUND,
size_type length) noexcept
: ptr_(array), len_(length) {} : ptr_(array), len_(length) {}
// Implicit conversion constructors // Implicit conversion constructors
template <size_t N> template <size_t N>
constexpr Span(T (&a)[N]) noexcept // NOLINT(google-explicit-constructor) constexpr Span(T( // NOLINT(google-explicit-constructor)
&a ABSL_ATTRIBUTE_LIFETIME_BOUND)[N]) noexcept
: Span(a, N) {} : Span(a, N) {}
// Explicit reference constructor for a mutable `Span<T>` type. Can be // Explicit reference constructor for a mutable `Span<T>` type. Can be
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment