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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|jwakely.gcc at gmail dot com       |mpolacek at gcc dot 
gnu.org
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's a front-end bug in the __is_convertible built-in.

Reduced:

template<bool B>
struct bool_constant { static constexpr bool value = B; };
using true_type = bool_constant<true>;
using false_type = bool_constant<false>;

template<typename T> struct is_void : false_type { };
template<> struct is_void<void> : true_type { };

template<bool> struct enable_if { };
template<> struct enable_if<true> { using type = void; };
template<bool B> using enable_if_t = typename enable_if<B>::type;

#ifndef NO_BUILTIN
  template<typename _From, typename _To>
    struct is_convertible
    : public bool_constant<__is_convertible(_From, _To)>
    { };
#else

  template<typename T> T&& declval();

  template<typename _From, typename _To,
           bool = is_void<_From>::value>
    struct __is_convertible_helper
    {
      typedef typename is_void<_To>::type type;
    };

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
  template<typename _From, typename _To>
    class __is_convertible_helper<_From, _To, false>
    {
      template<typename _To1>
        static void __test_aux(_To1) noexcept;

      template<typename _From1, typename _To1,
               typename = decltype(__test_aux<_To1>(declval<_From1>()))>
        static true_type
        __test(int);

      template<typename, typename>
        static false_type
        __test(...);

    public:
      typedef decltype(__test<_From, _To>(0)) type;
    };
#pragma GCC diagnostic pop

  /// is_convertible
  template<typename _From, typename _To>
    struct is_convertible
    : public __is_convertible_helper<_From, _To>::type
    { };
#endif

struct string_view { };

struct string
{
private:
  template<class T>
    using If_sv = enable_if_t<is_convertible<const T&, string_view>::value>;

public:
  void append(const string&) { }
  template<class T> If_sv<T> append(const T&) { }

  operator string_view() const { return {}; }
};


struct PrivateString : private string
{
  void f()
  {
    const auto& cthis = *this;
    static_cast<string&>(*this).append(cthis);
  }
};


conv.cc: In instantiation of 'struct is_convertible<const PrivateString&,
string_view>':
conv.cc:68:11:   required by substitution of 'template<class T> using
string::If_sv = enable_if_t<is_convertible<const T&, string_view>::value> [with
T = PrivateString]'
conv.cc:72:30:   required by substitution of 'template<class T>
string::If_sv<T> string::append(const T&) [with T = PrivateString]'
conv.cc:83:39:   required from here
conv.cc:16:28: error: 'string::operator sv_type() const' is inaccessible within
this context
   16 |     : public bool_constant<__is_convertible(_From, _To)>
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
conv.cc:74:3: note: declared here
   74 |   operator sv_type() const { return {}; }
      |   ^~~~~~~~


Using -DNO_BUILTIN it works, so I'll revert the library change to use
__is_convertible.

Reply via email to