Decltype cannot create member declared in template class

I am having a problem with code that could not be compiled for the external library that I am using. I believe the library compiles with gcc, but it does not compile for me with clang.

I can recreate the problem 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;
}

It 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 for non-static elements was added in C ++ 11. Does this apply to those declared in template classes?

  • Is this a compiler error? Or an example of inappropriate code working with gcc?

+4
source share
1 answer

Clang ​​ Clang 3.9.0: https://godbolt.org/g/zqFxL2

Standarteese:

8.2.3: ([expr.prim.req], [expr.typeid], [expr.sizeof], [expr.unary.noexcept], [dcl.type.simple], [temp]). . [: named ([expr.prim]) , ([basic.def.odr]). . - ]

+10

Source: https://habr.com/ru/post/1693885/


All Articles