[cfe-dev] Clang: Erroneous behavior on windows
Reid Kleckner
rnk at google.com
Mon Mar 23 14:22:08 PDT 2015
So, this was a bug. We forgot to make lambda call operators thiscall.
They're C++ method decls, and should clearly use that convention. I changed
in r233023 to reflect that.
Thanks for the report!
On Mon, Mar 23, 2015 at 2:44 AM, Sebastian Redl <
sebastian.redl at getdesigned.at> wrote:
> On 3/22/2015 6:25 PM, Daniel Berenyi wrote:
>
>> Dear All,
>>
>> //-----------------------------------------------
>> template<typename F>
>> decltype(auto) deduce(F f){ return &decltype(f)::operator(); }
>>
>> template<typename C, typename R, typename A> decltype(auto)
>> signaturehelper( R(C::*f)(A)const ) { return R(); }
>>
>> int main()
>> {
>> auto l = [](int x){return x*2;};
>> decltype(signaturehelper(deduce(l))) p;
>> }
>> //--------------------------------
>>
>> It fails with:
>> decltype(signaturehelper(deduce(l))) p;
>> ^~~~~~~~~~~~~~~
>> note: candidate template ignored: substitution failure [with C = (lambda
>> at main.cpp:9:11), R = float, A = int]
>> decltype(auto) signaturehelper(R(C::*f)(A)const) { return R(); }
>>
>> I've had exactly the same problem when I tried to find the argument type
> of a lambda. Here's how I worked around it:
>
> template <typename R, typename C, typename Arg, typename... Args>
> struct FirstArgumentImpl<R (C::*)(Arg, Args...) const>
> {
> using type = Arg;
> };
> // for Clang on Windows
> template <typename R, typename C, typename Arg, typename... Args>
> struct FirstArgumentImpl<R (__cdecl C::*)(Arg, Args...) const>
> {
> using type = Arg;
> };
>
> The issue appears to be that Clang gives the lambda's operator() a __cdecl
> calling convention instead of the default member __thiscall calling
> convention.
>
> Sebastian
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150323/84594192/attachment.html>
More information about the cfe-dev
mailing list