[libcxx-commits] [PATCH] D68952: Guard against possible overflow in span.subpan

Casey Carter via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 22 12:39:56 PDT 2019


CaseyCarter added inline comments.


================
Comment at: test/std/containers/views/span.sub/subspan.fail.cpp:35
+	{
+		auto s1 = sp_static.template subspan<5>(); // expected-error {{Offset out of range in span::subspan()}}
+		auto s2 = sp_dynamic.template subspan<5>(); // expected-error {{Offset out of range in span::subspan()}}
----------------
These `template` disambiguators should all be unnecessary since none of the object expressions have dependent type. In other words, `span<int>().subspan<0, 0>()` doesn't need a disambiguator since the compiler knows that `span<int>()` has type `span<int>` and it can see that `subspan` is a member template. This:
```
template<class T>
auto f() {
  return span<T>.template subspan<0, 0>();
```
on the other hand *does* need a disambiguator: `span<T>` has dependent type since `T` has dependent type. `span<T>` could be a specialization of `span` that the compiler hasn't even seen yet, so it can only guess what `span<T>.subspan` is.



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68952/new/

https://reviews.llvm.org/D68952





More information about the libcxx-commits mailing list