public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96204] New: gcc complains about private member access in SFINAE context
@ 2020-07-15  8:54 lts-rudolph at gmx dot de
  2020-07-15  8:56 ` [Bug c++/96204] " lts-rudolph at gmx dot de
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: lts-rudolph at gmx dot de @ 2020-07-15  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96204
           Summary: gcc complains about private member access in SFINAE
                    context
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lts-rudolph at gmx dot de
  Target Milestone: ---

gcc complains with following error in the example code:

main.cpp:59:72: error: 'void Child::setAttr(int)' is private within this
context
   59 | struct has_set_attr_method<T,
void_t<decltype(std::declval<T>().setAttr(1))>> {
      |                                              
~~~~~~~~~~~~~~~~~~~~~~~~~^~~
main.cpp:85:14: note: declared private here
   85 |         void setAttr(int x) {
      |              ^~~~~~~
main.cpp:59:72: error: 'void Child::setAttr(int)' is private within this
context
   59 | struct has_set_attr_method<T,
void_t<decltype(std::declval<T>().setAttr(1))>> {
      |                                              
~~~~~~~~~~~~~~~~~~~~~~~~~^~~
main.cpp:85:14: note: declared private here
   85 |         void setAttr(int x) {
      |              ^~~~~~~
main.cpp:59:72: error: 'void Child::setAttr(int)' is private within this
context
   59 | struct has_set_attr_method<T,
void_t<decltype(std::declval<T>().setAttr(1))>> {
      |                                              
~~~~~~~~~~~~~~~~~~~~~~~~~^~~
main.cpp:85:14: note: declared private here
   85 |         void setAttr(int x) {


Full code example:

---------------
template <typename, typename = void_t<>>
struct has_set_attr_method {
    static constexpr bool value = false;
};
template <typename T>
struct has_set_attr_method<T, void_t<decltype(std::declval<T>().setAttr(1))>> {
    static constexpr bool value = true;
};

struct Parent
{
    public:
        template<typename T>
            static void create()    {   
                auto obj = T::create();
                if constexpr(has_set_attr_method<T>::value) {
                    cout << "has setAttr" << endl;
                } else {
                    cout << "no setAttr" << endl;
                }
            }
};

struct Child : public Parent {
    public:
        friend class Parent;
        static auto create() {
            return Child();
        }

    private:
        void setAttr(int x) {
        }
};

int main(int argc, char const *argv[]) {
    Parent::create<Child>();
    return 0;
}

---------------

Interestingly the failure depends on "friend" declaration inside "Child".

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-11-30 10:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-15  8:54 [Bug c++/96204] New: gcc complains about private member access in SFINAE context lts-rudolph at gmx dot de
2020-07-15  8:56 ` [Bug c++/96204] " lts-rudolph at gmx dot de
2020-07-15 10:03 ` redi at gcc dot gnu.org
2020-07-15 10:05 ` redi at gcc dot gnu.org
2020-07-15 10:09 ` redi at gcc dot gnu.org
2021-06-25 12:43 ` ppalka at gcc dot gnu.org
2021-06-26 15:08 ` cvs-commit at gcc dot gnu.org
2021-06-26 15:12 ` ppalka at gcc dot gnu.org
2021-07-01  0:21 ` cvs-commit at gcc dot gnu.org
2022-05-25 19:50 ` Martin.Jansa at gmail dot com
2022-11-30 10:28 ` redi at gcc dot gnu.org

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).