public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "johelegp at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102174] New: Unused result of undefined behavior arithmetic is accepted during constant evaluation Date: Thu, 02 Sep 2021 11:07:54 +0000 [thread overview] Message-ID: <bug-102174-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102174 Bug ID: 102174 Summary: Unused result of undefined behavior arithmetic is accepted during constant evaluation Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: johelegp at gmail dot com CC: johelegp at gmail dot com Target Milestone: --- See https://godbolt.org/z/d38ozc91x. ```C++ #include <cstdint> constexpr bool f() { 1 / 0; 1.0 / 0; 1 % 0; INT32_MIN / INT32_C(-1); INT32_MIN * INT32_C(-1); INT32_MAX + INT32_C(1); INT16_C(INT32_MAX + INT32_C(1)); return true; } constexpr bool b{f()}; ``` ``` <source>: In function 'constexpr bool f()': <source>:3:5: warning: division by zero [-Wdiv-by-zero] 3 | 1 / 0; | ~~^~~ <source>:3:5: warning: statement has no effect [-Wunused-value] <source>:4:7: warning: division by zero [-Wdiv-by-zero] 4 | 1.0 / 0; | ~~~~^~~ <source>:4:7: warning: statement has no effect [-Wunused-value] <source>:5:5: warning: division by zero [-Wdiv-by-zero] 5 | 1 % 0; | ~~^~~ <source>:5:5: warning: statement has no effect [-Wunused-value] <source>:6:13: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow] 6 | INT32_MIN / INT32_C(-1); | ^ <source>:6:13: warning: statement has no effect [-Wunused-value] <source>:7:13: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow] 7 | INT32_MIN * INT32_C(-1); | ^ <source>:7:13: warning: statement has no effect [-Wunused-value] <source>:8:13: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow] 8 | INT32_MAX + INT32_C(1); | ^ <source>:8:13: warning: statement has no effect [-Wunused-value] In file included from /opt/compiler-explorer/gcc-11.2.0/lib/gcc/x86_64-linux-gnu/11.2.0/include/stdint.h:9, from /opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/cstdint:41, from <source>:1: <source>:9:21: warning: integer overflow in expression of type 'int' results in '-2147483648' [-Woverflow] 9 | INT16_C(INT32_MAX + INT32_C(1)); | ^ <source>:9:21: warning: statement has no effect [-Wunused-value] Compiler returned: 0 ```
next reply other threads:[~2021-09-02 11:07 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-02 11:07 johelegp at gmail dot com [this message] 2021-12-04 13:03 ` [Bug c++/102174] " pinskia 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-102174-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).