Skip to content

[libc++] [ranges] sized_range of iota_view<short, short> #67551

Closed
@jonathan-hopkins

Description

@jonathan-hopkins

Hi. The following code, when compiled with libc++, is unable to deduce the correct size type of iota_view. Changing short to a different integral type generates no errors.

#include <ranges>
#include <numeric>

int main() {
    static_assert(std::ranges::sized_range<std::ranges::iota_view<short, short>>, "short");
}

clang output:

In file included from <source>:1:
In file included from /opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/ranges:353:
In file included from /opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/drop_view.h:30:
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/iota_view.h:368:9: error: 'auto' in return type deduced as 'int' here but deduced as '__make_unsigned_t<int>' (aka 'unsigned int') in earlier return statement
        return std::__to_unsigned_like(__bound_sentinel_) - std::__to_unsigned_like(__value_);
        ^
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/size.h:55:29: note: in instantiation of member function 'std::ranges::iota_view<short, short>::size' requested here
    { _LIBCPP_AUTO_CAST(__t.size()) } -> __integer_like;
                            ^
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/size.h:55:7: note: in instantiation of requirement here
    { _LIBCPP_AUTO_CAST(__t.size()) } -> __integer_like;
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__utility/auto_cast.h:20:33: note: expanded from macro '_LIBCPP_AUTO_CAST'
#define _LIBCPP_AUTO_CAST(expr) static_cast<typename decay<decltype((expr))>::type>(expr)
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/size.h:54:3: note: while substituting template arguments into constraint expression here
  requires(_Tp&& __t) {
  ^~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/size.h:92:13: note: while checking the satisfaction of concept '__member_size<std::ranges::iota_view<short, short> &>' requested here
  template <__member_size _Tp>
            ^
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/size.h:92:13: note: while substituting template arguments into constraint expression here
  template <__member_size _Tp>
            ^~~~~~~~~~~~~
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/concepts.h:78:60: note: while checking constraint satisfaction for template 'operator()<std::ranges::iota_view<short, short> &>' required here
  concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
                                                           ^~~~~~
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/concepts.h:78:60: note: in instantiation of function template specialization 'std::ranges::__size::__fn::operator()<std::ranges::iota_view<short, short> &>' requested here
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/concepts.h:78:60: note: in instantiation of requirement here
  concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
                                                           ^~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-16.0.0/bin/../include/c++/v1/__ranges/concepts.h:78:39: note: while substituting template arguments into constraint expression here
  concept sized_range = range<_Tp> && requires(_Tp& __t) { ranges::size(__t); };
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:19: note: while checking the satisfaction of concept 'sized_range<std::ranges::iota_view<short, short>>' requested here
    static_assert(std::ranges::sized_range<std::ranges::iota_view<short, short>>, "short");
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Compiler returned: 1

Metadata

Metadata

Assignees

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.rangesIssues related to `<ranges>`rejects-valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions