Title
Lambdas and decltype
Status
nad
Section
7.5.6 [expr.prim.lambda]
Submitter
Jason Merrill

Created on 2009-08-31.00:00:00 last changed 184 months ago

Messages

Date: 2009-10-15.00:00:00

Rationale (October, 2009):

The consensus of the CWG was that this is not a sufficiently important problem to warrant changing the existing specification.

Date: 2022-11-20.07:54:16

The following case is ill-formed:

    int f (int&);
    void* f (const int&);

    int main()
    {
       int i;
       [=] ()-> decltype(f(i)) { return f(i); };
    }

The decltype(f(i)) is not of the form decltype((x)), and also not within the body of the lambda, so the special rewriting rule doesn't apply. So, the call in the decltype selects the first overload, and the call in the body selects the second overload, and there's no conversion from void* to int, so the return-statement is ill-formed.

This pattern is likely to arise frequently because of the retrictions on deducing the return type from the body of the lambda.

Daveed Vandevoorde: The pattern may be common, but it probably doesn't matter much in practice. It's most likely that overloaded functions that differ only in the cv-qualification of their parameters will have related return types.

History
Date User Action Args
2009-11-08 00:00:00adminsetmessages: + msg2483
2009-11-08 00:00:00adminsetstatus: open -> nad
2009-08-31 00:00:00admincreate