Typedef evaluation in class template

The following code compiles with g ++, but does not compile with clang.

struct X;

template <typename T>
struct Traits
{
    typedef typename Traits<T>::Container Container;
};

template <>
struct Traits<X>
{
    typedef std::vector<X *> Container;
};

int main()
{
    Traits<X>::Container container;
    return EXIT_SUCCESS;
}

clang error message:

main.cpp:9:30: error: no type named 'Container' in 'Traits<T>'

Should the compiler evaluate typedef without replacing the template parameter with the actual type? Which compiler is right?

clang: http://coliru.stacked-crooked.com/a/fef7725827074e4f

gcc: http://coliru.stacked-crooked.com/a/79e17031fcabcd83

+4
source share
1 answer
template <typename T>
struct Traits {
  typedef typename Traits<T>::Container Container;
};

it is poorly formed, no diagnostics are required. No T, the above (primary) specialization could lead to a valid code.

. - , . . , foo . , .

, , T (.. ) , .

+4

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


All Articles