clang/g++ 私有继承和using声明的区别

clang/g++ difference with private inheritance and using declaration

考虑以下代码:

#include <iostream>

struct Params { };

template <class T>
struct Base
{
    int data() const { return 42; }
};

template <template <class> class D, class P>
struct Middle : private D<P> // must be 'public' for g++
{
};

struct Final : public Middle<Base,Params>
{
    using Base<Params>::data;
};


int main() {

    Final f;

    std::cout << f.data() << std::endl;

    return 0;
}

此代码编译成功并打印 42clang and gives me compile time error on gcc

'int Base::data() const [with T = Params]' is inaccessible

在这种情况下,哪种实现更符合 C++ 标准?

海湾合作委员会是正确的。 [namespace.udecl]/17:

The access rules for inheriting constructors are specified in 12.9; otherwise all instances of the name mentioned in a using-declaration shall be accessible. In particular, if a derived class uses a using-declaration to access a member of a base class, the member name shall be accessible.