有多少个具有非类型模板参数的类模板的特化必须成为朋友?

Fed*_*dor 5 c++ templates friend language-lawyer

在下面的代码中,有一个struct A带有非类型模板参数的模板,并class B声明A<0>为其友元。然后使用成员函数A<x>::has_access()检查它是否有权访问 private B::p()

template<auto>
struct A {
    static constexpr bool has_access();
};

class B {
    void p() {}
    friend struct A<0>;
};

template<auto x>
constexpr bool A<x>::has_access() {
    return requires(B b) { b.p(); };
}

// #1: accepted by all
static_assert( A<0>::has_access() );
// #2: accepted by Clang
static_assert( A<1>::has_access() );
// #3: accepted by Clang and MSVC
static_assert( A<char(0)>::has_access() );
Run Code Online (Sandbox Code Playgroud)

计划接受程度存在分歧:

  1. A<0>::has_access()在我测试的所有编译器中都有true
  2. A<1>::has_access()仅在trueClang 中。
  3. A<char(0)>::has_access()仅在trueClang 和 MSVC 中。

演示: https: //gcc.godbolt.org/z/P5njvzGee

这里是哪个编译器?以后A要成为多少专业的朋友?Bfriend struct A<0>