c++ - What is this compiler error when using a lambda as a template parameter? -


edit:

this has been reported vs2012 c++ compiler bug on microsoft connect (link).

nov. 11, 2014: microsoft has responded saying fix bug should show in next major release of visual c++.


i've been struggling vs2012 compiler error message don't understand, trimmed down problem seems bare minimum.

i'm building following main.cpp using vs2012:

#include <utility>  template <typename t> struct {     t x;     a(a&& other) : x(std::move(other.x)) { }     a(t&& x) : x(std::move(x)) { } };  template <typename t> a<t> build(t&& x) {     return a<t>(std::move(x)); }  int main(int argc, char* argv[]) {     auto f = []()     {         return build([](){}); //error here     };     return 0; } 

the salient point i'm trying use lambda template type t of build function. error message is:

1>  main.cpp 1>c:\test\main.cpp(21): error c2664: 'a<t>::a(a<t> &&)' : cannot convert parameter 1 'a<t>' 'a<t> &&' 1>          1>          [ 1>              t=void (__cdecl *)(void) 1>          ] 1>          , 1>          [ 1>              t=main::<lambda_c3c618d445b3cb24eede9bf304860ad7>::()::<lambda_4240e93016e3e420ff8383c9350ae130> 1>          ] 1>          , 1>          [ 1>              t=void (__cdecl *)(void) 1>          ] 1>          reason: cannot convert 'a<t>' 'a<t>' 1>          1>          [ 1>              t=main::<lambda_c3c618d445b3cb24eede9bf304860ad7>::()::<lambda_4240e93016e3e420ff8383c9350ae130> 1>          ] 1>          , 1>          [ 1>              t=void (__cdecl *)(void) 1>          ] 1>          no user-defined-conversion operator available can perform conversion, or operator cannot called 

i've done research , looked page error message (link), still can't figure out problem is. please explain compiler error?


edit

something weird here. if change code in main this:

auto f = []() {     int* n = new int(0);     auto g = [=](){ return *n; };     *n++;     return build<decltype(g)>(std::move(g)); }; 

i error message suggesting t=int (__cdecl *)(void) in call build - mean decltype(g) giving me function pointer? huh? i'm capturing pointer value , modifying afterwards - shouldn't have create functor - , 1 has no cast function pointer? maybe i'm not understanding something.

see related: lambda expressions : n3290 draft


also, if is bug in vs2012 compiler, can think of workaround?

i can confirm using gcc (on linux), code compiles fine. i'd visualstudio seems source of error.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -