public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/42935] warn if a binary operation is performed on a type but the result is then casted to a larger type Date: Mon, 07 Jun 2010 18:05:00 -0000 [thread overview] Message-ID: <20100607180453.5800.qmail@sourceware.org> (raw) In-Reply-To: <bug-42935-1034@http.gcc.gnu.org/bugzilla/> ------- Comment #6 from manu at gcc dot gnu dot org 2010-06-07 18:04 ------- I think the condition of this warning should be: warn if a binary operation is performed on a type but the result is then implicitly converted to a larger type. The workaround for a valid case should be casting to the same type as the result beforehand. For example: unsigned val1 = 0x10000000, val2 = 0x100; unsigned long long val3 = val1 * val2; // "warning: binary operation '*' is performed on type 'unsigned int' but the result is converted to type 'double'" unsigned long long val4 = (unsigned) (val1 * val2); // silence This probably can be implemented in convert_and_check in c-common.c or in build_binary_op in c-typeck.c. I am not working on this. -- manu at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- GCC build triplet|i686-pc-cygwin | GCC host triplet|i686-pc-cygwin | GCC target triplet|i686-pc-cygwin | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42935
prev parent reply other threads:[~2010-06-07 18:05 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-02-02 10:10 [Bug c/42935] New: Warning "u64 = u32 * u32;" - i.e. not casting one u32 to u64 etienne_lorrain at yahoo dot fr 2010-02-24 0:17 ` [Bug c/42935] " manu at gcc dot gnu dot org 2010-02-24 9:45 ` etienne_lorrain at yahoo dot fr 2010-02-24 10:23 ` manu at gcc dot gnu dot org 2010-06-07 17:52 ` [Bug c/42935] warn if a binary operation is performed on a type but the result is then casted to a larger type manu at gcc dot gnu dot org 2010-06-07 17:53 ` manu at gcc dot gnu dot org 2010-06-07 18:05 ` manu at gcc dot gnu dot org [this message]
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=20100607180453.5800.qmail@sourceware.org \ --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).