N. *_*uch 5 alias templates friend c++11 clang++
我注意到 Clang 在以下场景中的一些独特行为:
有一个类foo包含一个私有成员函数模板function_template。foo 还将非嵌套结构bar声明为友元:
struct bar;
class foo {
friend struct ::bar;
template<typename T> void function_template() {}
};
Run Code Online (Sandbox Code Playgroud)
在 bar 内部声明了成员别名模板类型,该类型引用 foo 的成员函数模板的返回类型,如下所示:
struct bar {
template<typename T> using type = decltype(foo().function_template<T>());
}
Run Code Online (Sandbox Code Playgroud)
使用 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'
}
Run Code Online (Sandbox Code Playgroud)
这种行为符合标准吗?MSVC 和 GCC 都执行此实例化。Clang 还执行引用友元类的私有成员的其他别名模板的实例化。
我对别名模板行为的扩展测试可以在这里找到: https://ideone.com/cdB5lZ