How to declare a lambda's operator() as noreturn?

前端 未结 3 983
野趣味
野趣味 2021-01-17 08:51

How can the operator() of a lambda be declared as noreturn ?

Ideone accepts the following code:

#include   
         


        
3条回答
  •  自闭症患者
    2021-01-17 09:21

    [C++11: 7.6.3/1]: The attribute-token noreturn specifies that a function does not return. It shall appear at most once in each attribute-list and no attribute-argument-clause shall be present. The attribute may be applied to the declarator-id in a function declaration. The first declaration of a function shall specify the noreturn attribute if any declaration of that function specifies the noreturn attribute. If a function is declared with the noreturn attribute in one translation unit and the same function is declared without the noreturn attribute in another translation unit, the program is ill-formed; no diagnostic required.

    I concede that this wording, as is, doesn't prohibit the attribute from appearing elsewhere, but in concert with seeing no evidence anywhere in the standard for it, I don't think this is intended to work with lambda declarations.

    Therefore, Clang would be correct.

    It may or may not be telling that there was a patch proposal to Clang to allow GCC-style noreturn attributes on lambdas, but not the standard form.

    Unfortunately, this feature is not included in GCC's list of extensions, so I can't really see exactly what's going on here.

提交回复
热议问题