dimanche 16 juillet 2017

How could vc2015+ support operator implicit convertion with decltype(*)?

When I tested the code with http://ift.tt/2t4s2h6, I found the code can not be compiled success through vc2015 and vc2017. On the same time, clang 3.8.0 and g++ 5.4.0 works fine.

#include <functional>
#include <iostream>

namespace detail{
template<typename Lambda, typename Func>
struct lambda_wrapper;


template <typename Lambda, typename C, typename R>
struct lambda_wrapper<Lambda,R (C::*)(void) const>{
    static R call(void){
        Lambda x;
        return x();
    }
    //DEFINE_OPERATOR
    typedef decltype(&call) function_type; 
    operator decltype(&call) (void) { return &call;}
};


}//end of namespace detail

int main(void)
{
    typedef void(*Ptr)();
    auto l = [](){ std::cout << "im broked :(" << std::endl; };
    Ptr f=l;

    f();
}

The test code is on http://ift.tt/2unwgEt, error list follows:

source_file.cpp(17): error C2833: 'operator decltype' is not a recognized operator or type source_file.cpp(18): note: see reference to class template instantiation 'detail::lambda_wrapper' being compiled source_file.cpp(17): error C2059: syntax error: 'newline' source_file.cpp(17): error C2334: unexpected token(s) preceding '{'; skipping apparent function body Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64

Aucun commentaire:

Enregistrer un commentaire