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.