Warning specifically for a returning noreturn

LIU Hao lh_mouse@126.com
Wed Jul 5 05:40:13 GMT 2023


在 2023/7/5 09:40, Andrew Pinski via Gcc 写道:
> It is wrong to use noreturn on a function other than one which has a
> return type of void as documented.
> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute
> :
> ```
> It does not make sense for a noreturn function to have a return type
> other than void.
> ```

It makes sense for a callback or virtual function which requires a non-void return type, e.g.

```
class my_stream : public std::streambuf
   {
   protected:
     virtual
     int
     underflow() override;
   };

__attribute__((__noreturn__))   // [[noreturn]] won't work
int
my_stream::
underflow()
   {
     throw std::invalid_argument("not implemented");
   }
```



-- 
Best regards,
LIU Hao

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20230705/f97c02e5/attachment.sig>


More information about the Gcc mailing list