libstdc++: Make ranges::size and ranges::empty check for unbounded arrays
authorJonathan Wakely <jwakely@redhat.com>
Sun, 12 Dec 2021 21:16:25 +0000 (21:16 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 13 Dec 2021 11:15:41 +0000 (11:15 +0000)
commit55823c5a0ba50022d7fcc95e74ec293143810ef6
tree42fe968367bd37354d599b1ea8396344dba783f6
parentef5d671cd80a4afa4f74c3dfe2904c63f51fcfde
libstdc++: Make ranges::size and ranges::empty check for unbounded arrays

Passing IncompleteType(&)[] to ranges::begin produces an error outside
the immediate context, which is fine for ranges::begin, but it means
that we fail to enforce the SFINAE-able constraints for ranges::size and
ranges::size. They should not be callable for any array of unknown
bound, whether the type is complete or not. Because we don't enforce
that in their constraints, we get a hard error when they try to use
ranges::begin.

This simply adds explicit checks for arrays of unknown bound to the
constraints for ranges::size and ranges::empty. We only need to check it
for the __sentinel_size and __eq_iter_empty concepts, because those are
the ones that are relevant to arrays, and which try to use
ranges::begin.

libstdc++-v3/ChangeLog:

* include/bits/ranges_base.h (ranges::size, ranges::empty): Add
explicit check for unbounded arrays before using ranges::begin.
* testsuite/std/ranges/access/empty.cc: Check handling of unbounded
arrays.
* testsuite/std/ranges/access/size.cc: Likewise.
libstdc++-v3/include/bits/ranges_base.h
libstdc++-v3/testsuite/std/ranges/access/empty.cc
libstdc++-v3/testsuite/std/ranges/access/size.cc