Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jonathan-hopkins opened this issue Sep 27, 2023 · 2 comments · Fixed by #67819
Closed

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

jonathan-hopkins opened this issue Sep 27, 2023 · 2 comments · Fixed by #67819
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>` rejects-valid

Comments

@jonathan-hopkins
Copy link

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
@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Sep 27, 2023
@philnik777 philnik777 added rejects-valid ranges Issues related to `<ranges>` labels Sep 27, 2023
@ldionne
Copy link
Member

ldionne commented Sep 29, 2023

Godbolt: https://godbolt.org/z/95sP5KTb5

@ldionne ldionne self-assigned this Sep 29, 2023
ldionne added a commit to ldionne/llvm-project that referenced this issue Sep 29, 2023
We were incorrectly deducing the return type of size() because we were
not using ternary operators in the implementation (as the spec says).
Instead of deducing the common type of the expressions in the spec, we
would deduce potentially different return types and fail to compile.

Fixes llvm#67551
ldionne added a commit that referenced this issue Oct 4, 2023
We were incorrectly deducing the return type of size() because we were
not using ternary operators in the implementation (as the spec says).
Instead of deducing the common type of the expressions in the spec, we
would deduce potentially different return types and fail to compile.

Fixes #67551
@jonathan-hopkins
Copy link
Author

Thanks for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>` rejects-valid
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants