Return type deduction with multi-statement lambdas

前端 未结 2 1334
闹比i
闹比i 2021-01-17 23:11

I\'ve been writing code, and I\'ve recently found out that g++ doesn\'t warn me about a certain class of issue: per C++11 5.1.2.4, if your lambda is not a single return stat

相关标签:
2条回答
  • 2021-01-17 23:29

    GCC 4.8.1 (and possibly earlier) and clang 3.3 already implements it; fixing DR975.

    There is now a proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3386.html) to get it into C++1y

    0 讨论(0)
  • 2021-01-17 23:46

    That is because it is a defect in the standard, and will be changed (see DR 975):

    975 Restrictions on return type deduction for lambdas

    There does not appear to be any technical difficulty that would require the current restriction that the return type of a lambda can be deduced only if the body of the lambda consists of a single return statement. In particular, multiple return statements could be permitted if they all return the same type.

    I doubt if there is a way to turn it off.

    0 讨论(0)
提交回复
热议问题