[libcxx-commits] [PATCH] D100255: [libcxx][ranges] adds `range` access CPOs

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 30 09:58:59 PDT 2021


zoecarver added inline comments.


================
Comment at: libcxx/test/std/ranges/range.access/range.access.begin/incomplete.compile.verify.cpp:28
+  struct incomplete;
+  f<incomplete(&)[10]>();
+  // expected-error@*:* {{"`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."}}
----------------
cjdb wrote:
> zoecarver wrote:
> > cjdb wrote:
> > > zoecarver wrote:
> > > > I think it would make more sense to call `std::ranges::begin` directly here. Certainly don't use `__begin::__fn`, especially if it's not in a libc++ test (which this probably shouldn't be anyway).
> > > Do you mean something like `static_assert(requires { std::ranges::begin(std::declval<incomplete(&)[]>()) });`?
> > No I mean you could do something like:
> > ```
> > void test(incomplete(&arg)[]) {
> >   std::ranges::begin(arg);
> > }
> > ```
> > Or
> > 
> > ```
> > std::ranges::begin(std::declval<incomplete(&)[]>());
> > ```
> > This is how someone is actually going to be using the function object when we expect to see the error. 
> > 
> > Anyway, this isn't a big deal so either way is fine. 
> Since this is a test for SFINAE friendliness, I don't think I can achieve that (I did try).
If this is a test for SFINAE friendliness, then it is important that the above code I posted causes this to fail to compile. Luckily it appears that it does. I just tested this 

```
  std::ranges::begin(std::declval<Incomplete(&)[]>());
```

locally and it produced 

```
atic_assert failed due to requirement '__complete' "`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type."
        static_assert(__complete, "`std::ranges::begin` is SFINAE-unfriendly on arrays of an incomplete type.");
        ^             ~~~~~~~~~~
/Users/zoecarver/Developer/llvm-source/llvm-project/libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp:59:21: note: in instantiation of function template specialization 'std::ranges::__begin::__fn::operator()<Incomplete []>' requested here
  std::ranges::begin(std::declval<Incomplete(&)[]>());
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100255



More information about the libcxx-commits mailing list