Return type deduction with multi-statement lambdas

前端 未结 2 1335
闹比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: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.

提交回复
热议问题