Is my book's discussion of lambda return types wrong?

后端 未结 5 484
误落风尘
误落风尘 2020-12-07 00:59

My book says this:

Lambdas with function bodies that contain anything other than a single return statement that do not specify a return type return vo

5条回答
  •  爱一瞬间的悲伤
    2020-12-07 01:40

    The book accurately reflects the rules in draft n3290 of the Standard. Perhaps your compiler implemented a different draft.

    In section 5.1.2p4, the draft reads

    If a lambda-expression does not include a trailing-return-type, it is as if the trailing-return-type denotes the following type:

    • if the compound-statement is of the form { attribute-specifier-seqopt return expression ; } the type of the returned expression after lvalue-to-rvalue conversion, array-to-pointer conversion, and function-to-pointer conversion;
    • otherwise, void.

    The syntactic construct attribute-specifier-seq may be alignas or the double-bracketed attributes. Not variable declarations.

    Draft n3485, which followed publication of C++11 (i.e. it is work in progress toward C++1y), contains the same wording. I don't know if there was a different rule in some draft earlier than n3290.

提交回复
热议问题