This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/82478] Rejects valid access to private member type that should be allowed by friend


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

Alexander Zaitsev <zamazan4ik at tut dot by> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zamazan4ik at tut dot by

--- Comment #6 from Alexander Zaitsev <zamazan4ik at tut dot by> ---
One more problematic case: 

#include <type_traits>

class A {
    int a;
    friend class B;
};

class B {
    public:

    template <class T, class = void>
    struct trait: std::false_type {};

    template <class T>
    struct trait<T, std::void_t<decltype(std::declval<T&>().a)>>:
std::true_type {};
};

int main() {
    static_assert(B::trait<A>{});
    return 0;
}


On clang(trunk) this code works well. On gcc(trunk) we have: 

prog.cc: In function 'int main()':
prog.cc:15:61: error: 'int A::a' is private within this context
     struct trait<T, std::void_t<decltype(std::declval<T&>().a)>>:
std::true_type {};
                                          ~~~~~~~~~~~~~~~~~~~^
prog.cc:4:9: note: declared private here
     int a;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]