我在以下场景中注意到了Clang的一些独特行为:

有一个类foo,它包含一个私有成员函数模板function_template . foo还将非嵌套结构栏声明为friend:

struct bar;
class foo {
    friend struct ::bar;
    template<typename T> void function_template() {}
};

在bar的内部声明了成员别名模板类型,它引用了foo的成员函数模板的返回类型,如下所示:

struct bar {
   template<typename T> using type = decltype(foo().function_template<T>());
}

使用clang,编译器无法为任何模板参数实例化公共别名模板bar :: type:

#include <typeinfo>
#include <iostream>
int main {
    std::cout << typeid(bar::type<int>).name() << std::endl;
    // error : 'function_template' is a private member of 'foo'
}

Is this behaviour standard conforming? MSVC和GCC都执行此实例化 . Clang还执行其他别名模板的实例化,这些模板引用了友元类的私有成员 .

我可以在此处找到我对别名模板行为的扩展测试:https://ideone.com/cdB5lZ