public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/107049] error: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator __sv_type() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; __sv_type = std::basic_string_view<char>]’ is inaccessible within this context
Date: Tue, 27 Sep 2022 08:20:01 +0000	[thread overview]
Message-ID: <bug-107049-4-mdRNTqjZZ6@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107049-4@http.gcc.gnu.org/bugzilla/>

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.

  parent reply	other threads:[~2022-09-27  8:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27  7:54 [Bug libstdc++/107049] New: " marxin at gcc dot gnu.org
2022-09-27  7:55 ` [Bug libstdc++/107049] " marxin at gcc dot gnu.org
2022-09-27  7:56 ` marxin at gcc dot gnu.org
2022-09-27  8:20 ` redi at gcc dot gnu.org [this message]
2022-09-27  8:28 ` redi at gcc dot gnu.org
2022-09-27  8:33 ` redi at gcc dot gnu.org
2022-09-27  8:41 ` [Bug c++/107049] " redi at gcc dot gnu.org
2022-09-27 10:35 ` redi at gcc dot gnu.org
2022-09-27 13:00 ` cvs-commit at gcc dot gnu.org
2022-09-27 13:01 ` redi at gcc dot gnu.org
2022-09-27 14:19 ` ville.voutilainen at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107049-4-mdRNTqjZZ6@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).