Skip to content

Commit

Permalink
Remove nullability from Span::{pointer,iterator}
Browse files Browse the repository at this point in the history
These are in some sense correct (begin()/end() can be null for empty spans), but
don't capture the critical contract that begin() is only null when end() is.
This leads to foreach loops over spans being considered unsafe.

Long-term we may want to express such constraints somehow, but for now giving
these pointers unknown nullability is the best we can do.

PiperOrigin-RevId: 591191038
Change-Id: I1f02e068a445c0ca5996a9212477b64393ef4161
  • Loading branch information
sam-mccall authored and copybara-github committed Dec 15, 2023
1 parent a7e3daf commit 27478af
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions absl/types/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ class Span {
public:
using element_type = T;
using value_type = absl::remove_cv_t<T>;
using pointer = absl::Nullable<T*>;
using const_pointer = absl::Nullable<const T*>;
// TODO(b/316099902) - pointer should be Nullable<T*>, but this makes it hard
// to recognize foreach loops as safe.
using pointer = T*;
using const_pointer = const T*;
using reference = T&;
using const_reference = const T&;
using iterator = pointer;
Expand Down

0 comments on commit 27478af

Please sign in to comment.