public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "admin at computerquip dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113852] New: -Wsign-compare doesn't warn on unsigned result types Date: Fri, 09 Feb 2024 16:10:12 +0000 [thread overview] Message-ID: <bug-113852-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113852 Bug ID: 113852 Summary: -Wsign-compare doesn't warn on unsigned result types Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: admin at computerquip dot com Target Milestone: --- I haven't quite figured out the pattern here so the title may not be great. Some code may help explain better: https://godbolt.org/z/d8cqd1WqP ``` #include <iostream> #include <limits> #include <cinttypes> int main() { uint16_t a1 = std::numeric_limits<unsigned short>::max(); uint16_t a2 = std::numeric_limits<unsigned short>::max(); /* a1 * a2 should be 4294836225 in math terms */ uint64_t a3 = 4294836225; /* * The result of (a1 * a2) is of type int and the result is negative. * (a1 * a2) ends up as some bogus high number because the common * type here ends up as uint64_t and sign-extension occurs. */ if ((a1 * a2) > a3) { std::cout << "this will print\n"; } } ``` Some observations I've noticed: * If either a1 or a2 are constexpr, the warning will occur. * This used to warn up until 8.1. * Clang also doesn't warn here but MSVC will with /W3 or higher. * This seems like a slight variation of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101645
next reply other threads:[~2024-02-09 16:10 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-09 16:10 admin at computerquip dot com [this message] 2024-02-09 16:15 ` [Bug c++/113852] " admin at computerquip dot com 2024-02-09 16:38 ` redi at gcc dot gnu.org 2024-02-09 16:40 ` redi at gcc dot gnu.org 2024-02-09 16:42 ` redi at gcc dot gnu.org 2024-02-09 16:43 ` redi at gcc dot gnu.org 2024-02-12 8:31 ` rguenth at gcc dot gnu.org 2024-02-12 16:36 ` admin at computerquip dot com 2024-02-13 8:30 ` rguenther at suse dot de
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-113852-4@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).