C++ Logo

std-discussion

Advanced search

Re: Need your input on waring when we use 'using' clause and [[noreturn]]

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 22 Apr 2022 10:22:47 +0200
czw., 21 kwi 2022 o 19:40 Jason McKesson via Std-Discussion
<std-discussion_at_[hidden]> napisaƂ(a):
>
> What you're asking for would essentially require attributes to become a part of a function's signature. I don't think this is a door that should be opened.
>

Why not make a pointer to function `[[noreturn]]` same as `[[maybe_unused]]`?
```
using Ptr = void (*) () noexcept;
using PtrNr [[noreturn]] = void (*) () noexcept;
PtrNr pnr = foo;
[[noreturn]] Ptr p = pnr;
```
Logic will be bind to name rather than to type. With this we could
propagate this information without breaking type system as:
```
Ptr a = bar;
PtrNr b = a; //only warning there could be
```
still compile as `Ptr` and `PtrNr` is the same type, but differ by
applied attributes to name.


Another solution is allow to mark this on call site:
```
void bar()
{
  [[noreturn]] foo();
}
```

> As Giuseppe stated, the warning message can be turned off by annotating the calling function's implementation (which you already statically stated is [[noreturn]]) with [[unreachable]]. It's annoying perhaps, but given that these are very isolated corner cases, the motivation for an actual language change (particularly relating to function types) is pretty minimal.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2022-04-22 08:22:57