Skip to content
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

[libc++][ranges] ranges::to can have non-class return type #132133

Open
frederick-vs-ja opened this issue Mar 20, 2025 · 1 comment · May be fixed by #132528
Open

[libc++][ranges] ranges::to can have non-class return type #132133

frederick-vs-ja opened this issue Mar 20, 2025 · 1 comment · May be fixed by #132528
Labels
accepts-invalid libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`

Comments

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Mar 20, 2025

Currently, this ill-formed program which violates [range.utility.conv.to]/1 and [range.utility.conv.adaptors]/1 isn't rejected when using libc++ (Godbolt link):

#include <concepts>
#include <ranges>

int main() {
  struct R {
    int* begin() const;
    int* end() const;

    operator int() const { return 0; }
  };

  std::same_as<int> auto m [[maybe_unused]] = std::ranges::to<int>(R{});
  std::same_as<int> auto n [[maybe_unused]] = R{} | std::ranges::to<int>();
}

It's weird that the "class" part is mentioned in comments but not actually implemented.

// Mandates: C is a cv-unqualified class type.
static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
static_assert(
!is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");

// Mandates: C is a cv-unqualified class type.
static_assert(!is_const_v<_Container>, "The target container cannot be const-qualified, please remove the const");
static_assert(
!is_volatile_v<_Container>, "The target container cannot be volatile-qualified, please remove the volatile");

Note that libstdc++ and MSVC STL also reject union types by only using is_class_v, despite that the term "class type" in the C++ core language specification also covers union types. Perhaps we should also only accept non-union class types here and submit an LWG issue for this.

Edit: LWG4229

@frederick-vs-ja frederick-vs-ja added accepts-invalid libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>` labels Mar 20, 2025
Yuzhiy05 added a commit to Yuzhiy05/llvm-project that referenced this issue Mar 22, 2025
@Yuzhiy05 Yuzhiy05 linked a pull request Mar 22, 2025 that will close this issue
@philnik777
Copy link
Contributor

I don't think we should reject unions. There is no fundamental difference between struct S { union {} } and union S {}, but we would reject the latter while accepting the former.

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

Successfully merging a pull request may close this issue.

2 participants