MSVC: explicit template instantiation fails,

I just ran into a problem with MSVC (version 12 Update 5):

An explicit copy of a template function is not performed if this function has an overload that is disabled via SFINAE. However, calling this function (thus the implication creating the instance) works.

Code example:

#include <type_traits>

template <typename T>
std::enable_if_t< std::is_integral<T>::value,  // test is true for T=int
void> foo( T& ) {}

template <typename T>
std::enable_if_t< std::is_pointer<T>::value,  // test is false for T=int
void> foo( T& ) {}

void bar( )
{
  int i;
  foo( i );  // calls foo( int& ) (obviously), compiles fine
}
template void foo( int& );  // explicit instantiation, throws compiler error

Compiler Error: error C2794: 'type' : is not a member of any direct or indirect base class of 'std::enable_if<false,void>'. The same code looks great with GCC (except for the lack of the main function): live on Ideone .

Is this an MSVC error? Is there any way to make these explicit template instances?

+4
source share
1 answer

, , ( ) .obj :

namespace {
  template <typename T>
  void helper( T& A )
  {
    foo( A );
  }

  template void helper( int& );
}

, helper(..) . "" foo(..) helper(..), MSVC .

EDIT: , , MSVC ( Niall), , MSVC, , .

0

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


All Articles