New issue
Advanced search Search tips

Issue 866894 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

[base] Mutable spans should require explicit construction

Project Member Reported by jdoerrie@chromium.org, Jul 24

Issue description

While not specified by the std::span proposal, creating mutable base::spans should require explicit construction. 

As a motivating example, look at the following code:

void Foo(base::span<int> span) {
  span[0] = 0xF00;
}

...

std::vector<int> bar = {1, 2, 3};
Foo(bar);


It is not obvious to the caller that Foo() mutates |bar|. Functionally this code is equivalent to the following, which is banned by the style-guide due to the usage of a non-const reference:

void Foo(std::vector<int>& vec) {
  vec[0] = 0xF00;
}

...

std::vector<int> bar = {1, 2, 3};
Foo(bar);

Likely because of this, absl::Span<T> requires explicit construction when T is non-const [1], whose behavior I think we should mirror here. Furthermore, we should then update the corresponding make_span functions to invoke an explicit constructor.

[1] https://github.com/abseil/abseil-cpp/blob/7aa411ceafc1272a28579cca739a97a2fb79055a/absl/types/span.h#L297
 

Sign in to add a comment