Skip to content

Commit

Permalink
pw_span: Disallow construction from std::nullptr_t
Browse files Browse the repository at this point in the history
C++20's std::span does not allow constructing spans from std::nullptr_t.
Disallow that in Pigweed's span for forward compatibility.

Change-Id: I99556a982f952b7fb5f64360b3a230838925ea72
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/96562
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
  • Loading branch information
255 authored and CQ Bot Account committed Jun 6, 2022
1 parent e072181 commit 20c1345
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pw_span/public/pw_span/internal/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ class span : public pw_span_internal::ExtentStorage<Extent> {
_PW_SPAN_ASSERT(Extent == dynamic_extent || Extent == size);
}

// Prevent construction from nullptr, which is disallowed by C++20's std::span
constexpr span(std::nullptr_t data, size_t size) = delete;

// Artificially templatized to break ambiguity for span(ptr, 0).
template <typename = void>
constexpr span(T* begin, T* end) noexcept : span(begin, end - begin) {
Expand Down

0 comments on commit 20c1345

Please sign in to comment.