Template Template Template in VS2015

I ran into a curious problem. Given the template class and template function:

template<typename L, typename T>
class TemplateClass
{
public:

   int operator()()
   {
      return 1;
   }
};

template<typename K, template<typename L, 
                              typename T = int> class TemplateCl>
TemplateCl<K> getTemplateClass(TemplateCl<K> _cls)
{
   TemplateCl<K> cls;
   return cls;
}

int main()
{
    auto templateClass = TemplateClass<int,int>();
    auto rTemplateClass = getTemplateClass<int>(templateClass);
    return 0;
}

      

This code is compiled by Clang, but when I try to compile with VS2015 it fails:

Severity    Code    Description Project File    Line    Suppression State
Error   C2672   'getTemplateClass': no matching overloaded function found   cpp11_cpp14_cpp17   d:\projects_programing\__testing\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17.cpp  682 
Severity    Code    Description Project File    Line    Suppression State
Error   C2893   Failed to specialize function template 'TemplateCl<K,int> getTemplateClass(TemplateCl<K,int>)'  cpp11_cpp14_cpp17   d:\projects_programing\__testing\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17.cpp  682 

      

This code only compiles with the following changes:

template<typename L, typename T = int>
class TemplateClass
{
public:

   int operator()()
   {
      return 1;
   }
};

      

The strangest situation is when it even compiles with the following modification:

template<typename L, typename T = float>
class TemplateClass
{
public:

   int operator()()
   {
      return 1;
   }
};

      

Is this a problem in the VS2015 compiler? Does anyone know why VS2015 has this behavior?

+3


source to share





All Articles