I am having an issue with code failing to compile for an external library I am using. I believe that library compiles fine with gcc, but it fails to compile for me with clang.
I can recreate the issue as follows
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;
}
This fails to compile on clang with the following error
error: invalid use of non-static data member 'a' printf("Result %d", std::numeric_limits<decltype(B::a)>::max());
My questions are as follows:
What is the expected behavior?
decltype on non-static members was added in c++11. Does this apply to those declared in template classes?
Is this a compiler bug? Or an example of non-conformant code working with gcc?