https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94049

            Bug ID: 94049
           Summary: For better diagnostics CPOs should not use concepts
                    for operator()
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Consider the following code:

#include <algorithm>
void foo0() {
    int t = 0;
    std::ranges::begin(t);
}


Diagnostics for it is mostly unreadable and points to the internals of
libstdc++ https://godbolt.org/z/c-RwuY .

This could be significantly improved. Right now the `requires` clause on
`std::ranges::__cust_access::_Begin::operator()` duplicates the body of the
function. So instead of such duplication all the requirements could be just
asserted in the body:


template<typename _Tp>
constexpr auto
operator()(_Tp&& __t) const noexcept(_S_noexcept<_Tp>()) {
      static_assert(__maybe_borrowed_range<_Tp>, "Not a borrowed range or
lvalue");
  if constexpr (is_array_v<remove_reference_t<_Tp>>) {
    ...
  } else if constexpr (__member_begin<_Tp>)
    return __t.begin();
  else if constexpr (__adl_begin<_Tp>)
    return begin(__t);
  else
    static_assert(!sizeof(_Tp), "_Tp should have either a member begin() or an
begin(_Tp&) should be in the namespace of _Tp");
}


This gives a much better diagnostics: https://godbolt.org/z/kmLGb7
All the CPOs could be improved in that manner

Reply via email to