我遇到了代码无法为我正在使用的外部库编译的问题.我相信库用gcc编译得很好,但它无法用clang为我编译.
我可以重新创建如下问题
template <class T>
class A {
public:
struct B {
int a;
};
void test();
private:
T _t;
};
template <class T>
void A<T>::test()
{
printf("Result %d", std::numeric_limits<decltype(B::a)>::max());
}
int main(int argc, char** argv)
{
auto t = A<int>();
t.test();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这无法在clang上编译时出现以下错误
error: invalid use of non-static data member 'a' printf("Result %d", std::numeric_limits<decltype(B::a)>::max());
Run Code Online (Sandbox Code Playgroud)
我的问题如下:
预期的行为是什么?
在c ++ 11中添加了非静态成员的decltype.这适用于模板类中声明的那些吗?
这是编译器错误吗?或者使用gcc的不符合代码的示例?