[PATCH] D37667: [C++14][Sema] Disallow decltype(auto) deduction for lambdas

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 10 13:44:57 PDT 2017


rsmith added a comment.

`decltype(auto) lambda = []{};` and `decltype(auto) list = {0,1};` seem like very different situations to me; in the latter case, the initializer is not even an expression.

The rule that bans `decltype([]{})` is that a *lambda-expression* shall not appear in an unevaluated operand. But the initializer in `decltype(auto) lambda = []{};` is not an unevaluated operand. The relevant rule is [dcl.type.auto.deduct]p5, which says: "The type deduced for T is determined as described in 10.1.7.2, as though e had been the operand of the decltype." -- so, while this is certainly not completely clear, this suggests that we only consider the expression as the operand of decltype for the purpose of determining the type, not for the purpose of determining whether the deduction is valid. And certainly seems to be the interpretation that is more friendly to users.


https://reviews.llvm.org/D37667





More information about the cfe-commits mailing list