public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "f.heckenbach@fh-soft.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/69818] warn for C++ functional cast expression on pointer or reference (i.e. add -Wfunctional-cast) Date: Sun, 23 Jan 2022 14:24:04 +0000 [thread overview] Message-ID: <bug-69818-4-CGxiFK7SXj@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-69818-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69818 Frank Heckenbach <f.heckenbach@fh-soft.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |f.heckenbach@fh-soft.de --- Comment #8 from Frank Heckenbach <f.heckenbach@fh-soft.de> --- Some such cases, including the original example, will run afoul of aliasing rules and at least produce a warning about that. However, that's not the case when the target is char &, since char is explicitly allowed to alias. So here's an example that doesn't produce any kind of warning with any option I tried: #include <iostream> int main () { float x = 1.2345f; using T = char &; std::cout << +T (x); } It outputs 25 on x86_64 (LE) rather than 1 as with a value cast to char. I agree that it may occur unnoticed in generic programming where a type parameter may easily become of reference type. I don't see any reason why someone would intentionally want to use this "feature" -- if one wants a reinterpret cast, one should write reinterpret_cast. So I agree a warning would be very useful -- I'd even say it should be included in -Wall or -Wextra if not on by default. See also: https://quuxplusone.github.io/blog/2020/01/22/expression-list-in-functional-cast/
next parent reply other threads:[~2022-01-23 14:24 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-69818-4@http.gcc.gnu.org/bugzilla/> 2022-01-23 14:24 ` f.heckenbach@fh-soft.de [this message] 2023-03-18 2:27 ` egallager at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-69818-4-CGxiFK7SXj@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).