Access to private definitions in the base offer of a friend class template

Is it legal in C ++ to create a specification for a base class of a class template Bdepending on the private definitions of a class Athat is friendly with the class template B? Code example:

struct Empty {};

template <typename T>
struct B;

struct A
{
    friend struct B<A>;

private:
    using Base = Empty;
};

template <typename T>
struct B : T::Base
{
};

int main()
{
    B<A> test;
    return 0;
}

Link Godbolt: https://godbolt.org/g/HFKaTQ

The code compiles using the Clang trunk (and older versions) and MSVC 19 (VS 2017), but it does not compile with the GCC trunk (and older version):

test.cpp: In instantiation of 'class B<A>':
test.cpp:21:7:   required from here
test.cpp:15:8: error: 'using Base = class Empty' is private within this context
 struct B : T::Base
        ^
test.cpp:11:20: note: declared private here
  using Base = Empty;
                    ^

Which compiler is wrong?

EDIT: , GCC, B ( ). , . cppreference : " ( ++ 11)"

+4
1

, GCC. 82613.

0

Source: https://habr.com/ru/post/1687758/


All Articles