I get what seems like a Visual Studio error when compiling a time test if the type with the default template parameter has some property. In the minimum example below, I use std::is_integer .
When compiling the following program with Visual Studio 2017
#include <type_traits> #include <utility> #include <algorithm> template<typename U, typename Enabled = typename std::enable_if<std::is_integral<U>::value>::type> struct wrapper { }; template<typename U, typename storage_type> using is_small = std::is_void<typename std::enable_if < (sizeof(wrapper<U, char>) <= sizeof(storage_type)) >::type>;
I get the following output
1>bug.cpp(13): error C2027: use of undefined type 'wrapper<U,char>' 1>bug.cpp(13): note: see declaration of 'wrapper<U,char>'
The same program compiles on g ++ 6.1.
The program compiles in Visual Studio when the default option Enable is removed. In addition, when I execute the same sizeof(...)<=sizeof(...) tags in the next member function of the template, the program compiles the penalty (with is_small ).
struct c { template<typename U, typename storage_type> typename std::enable_if<(sizeof(wrapper<U, char>) <= sizeof(storage_type))>::value foo(U u, storage_type t) {} };
Somehow the problem is with the definition of is_small .
Does anyone know what the problem is? Is this a Visual Studio bug? Is there a workaround?
Edit
Small version:
template<class, class> struct A { }; template<int> struct B { }; template<class T> constexpr auto x = sizeof(A<T, int>);
A possible workaround would be to use x instead of is_small .
Error report submitted: https://developercommunity.visualstudio.com/content/problem/204504/issues-with-sizeof-alias-templates-and-virtual-fun.html