g++ and clang++ (with libc++) different behaviour with template template class specialization

时间:2016-04-04 17:08:35

标签: c++ c++11 language-lawyer variadic-templates clang++

I'm playing 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 the libc++; when it uses the libstdc++, clang++ seems to behave as such as g++) related with a template template specialization for a template class.

The following 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 the libstdc++ but, adding -stdlib=libc++, gives 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 seems connected to the second and the third template parameter (with default values) of std::set. In fact, adding a variadic template parameter to the definition of the specialization of the class, in this way

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

both g++ and clang++ (with libstdc++ and with libc++) compile without errors.

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

g++? clang++ (with libc++)?

Or I came across something not defined by the standard?

0 个答案:

没有答案