G ++ and clang ++ (with libC ++) different behavior using template template template

I play with C ++ 11 and I came across a difference in behavior between g ++ 4.9.2 and clang ++ 3.5 (but only when it uses libC ++; when it uses libstdC ++, clang ++ seems to behave as such g ++) associated with the specialization of the template template for the template class.

Below is a trivial example

#include <set> template <typename X> class foo; template <template<typename, typename ...> class C, typename X> class foo<C<X>> {}; int main () { foo<std::set<int>> f; return 0; } 

g ++ compiles without problems; clang ++ compiles without problems with libstdc ++, but adding -stdlib=libc++ produces the following error:

 test.cpp:13:24: error: implicit instantiation of undefined template 'foo<std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> > >' foo<std::set<int>> f; ^ test.cpp:5:10: note: template is declared here class foo; ^ 1 error generated. 

The problem is related to the second and third template parameters (with default values) std::set . In fact, adding a variation pattern parameter to the class specialization definition, thus

 template <template<typename, typename ...> class C, typename X, typename ... Others> class foo<C<X, Others...>> {}; 

both g ++ and clang ++ (with libstdC ++ and libC ++) compile without errors.

So my question is: according to the standard, who is right?

g ++? clang ++ (with lib ++)?

Or did I come across something not defined by the standard?

+5
source share

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


All Articles