public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98660] New: -Wold-style-cast should not warn on casts that look like (decltype(x))(x)
@ 2021-01-13 17:56 gasper.azman at gmail dot com
  2021-01-14  0:42 ` [Bug c++/98660] " vanyacpp at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gasper.azman at gmail dot com @ 2021-01-13 17:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98660

            Bug ID: 98660
           Summary: -Wold-style-cast should not warn on casts that look
                    like (decltype(x))(x)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gasper.azman at gmail dot com
  Target Milestone: ---

Dear GCC wizards,

Recently, the use of std::forward has been idiomatically replaced by the
following:

```
template <typename T>
void george(T&& x) {
   john((T&&)x); // means std::forward<T>(x)
}
```

Casting an `x` to `decltype(x)` is far shorter and faster to compile (which
matters since it's done in unevaluated contexts A LOT). For an example, observe
the usage in libunifex, the in-progress research implementation of the
executors proposal:

https://github.com/facebookexperimental/libunifex/blob/master/include/unifex/tag_invoke.hpp

Unfortunately, the only real way to combine this fairly important exception to
the general rules of "no c-style casts" is to disable -Wold-style-cast.

It would be a great benefit if I could leave that warning enabled, and sleep
soundly in the knowledge I didn't mistype the forwarding expression if gcc
checked for me that the type I'm casting to is, in fact, `decltype(x)`, and
complain otherwise.

Please consider this refinement for a future release of GCC.

Thank you.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-16 21:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 17:56 [Bug c++/98660] New: -Wold-style-cast should not warn on casts that look like (decltype(x))(x) gasper.azman at gmail dot com
2021-01-14  0:42 ` [Bug c++/98660] " vanyacpp at gmail dot com
2021-01-14 11:39 ` gasper.azman at gmail dot com
2021-01-16 21:09 ` egallager at gcc dot gnu.org
2021-01-16 21:54 ` gasper.azman at gmail dot com
2021-01-16 21:55 ` gasper.azman at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).