SunBlack wrote:

I came across it because of #156058. I think the conversion can already be 
useful now, but restrictions could be imposed.

> `std::span` has a capability gap with a const reference to a `std::vector` 
> until C++26 as `std::span` cannot be constructed from an initializer list. 
> Should this be a C++26 check?

I guess you mean cases like this:
```cpp
// before
void print(const std::vector<int>& values) {
    for (int v : values) std::cout << v << " ";
}

// after
void print(std::span<const int> values) {
    for (int v : values) std::cout << v << " ";
}

print({1, 2, 3, 4});
```
Could the test be made configurable for this purpose?

Option 1) By default, it only reports methods if they are within a compilation 
unit and thus more visible for the check. In our tests, for example, we often 
have vectors with enum values that could be stored in a `constexpr std::array` 
instead of a `std::vector`. If values are not passed as an initializer list 
anywhere, you could safely switch.
Option 2) It warns everywhere. You don't normally have large initializer lists, 
so it shouldn't matter if you first store it in a separate variable, which 
increases the scope but makes the method more flexible.

And in principle: You can always disable any check if you don't like it ;-)

> Another capability gap is that a span doesn't seem to have bounds-checking 
> until C++26 and I'm not sure if the bounds-checking works for `std::vector`

Isn't that only relevant if an `at()` occurs in the method that is to be 
adapted? `std::vector::operator[]` does not have the check either, so it would 
only be a breaking change if `at()` is used. In that case, the transformation 
proposal could also be rejected.

https://github.com/llvm/llvm-project/pull/140001
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to