VS2013 - decltype of class method does not work as default template parameter does not work

228 Views Asked by At

I have a following piece of code:

template<typename T1,
         typename T2 = decltype(&T1::method)>
struct Foo {};

struct Bar
{
  void method() { }
};

template<class T> Foo<T> foo(T&)
{
  return Foo<T>();
}

int main()
{           
  Bar t;
  foo(t);
}

In short, I want to use decltype of a method as a default template parameter, and VS isn't happy about it:

source.cpp(18): error C2893: Failed to specialize function template 'Foo<T,T::method> foo(T &)'
      With the following template arguments:
      'T=Bar'

On the other hand gcc and clang are fine with this (http://ideone.com/VuMZaO). Also, moving decltype to foo definition resolves this error.

So - is it a bug in MSVC?

0

There are 0 best solutions below