public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "xmh970252187 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106294] New: GCC accepts the undefined behavior operation in a constant expression Date: Thu, 14 Jul 2022 12:15:29 +0000 [thread overview] Message-ID: <bug-106294-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106294 Bug ID: 106294 Summary: GCC accepts the undefined behavior operation in a constant expression Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: xmh970252187 at gmail dot com Target Milestone: --- ````cpp enum A {a = 0}; constexpr A e = static_cast<A>(1024); ```` According to [expr.static.cast p10 > If the enumeration type does not have a fixed underlying type, the value is unchanged if the original value is within the range of the enumeration values ([dcl.enum]), and **otherwise, the behavior is undefined**. [dcl.enum] p8 defines the range of the enumeration values, which says > Otherwise, the values of the enumeration are the values representable by a hypothetical integer type with **minimal** width M such that all enumerators can be represented. In this case, it is sufficient to represent the value `0` of the unique enumerator if `M` is `1`. Apparently, the value `1024` cannot be representable in the hypothetical integer type with minimal width M. So, the full-expression of the initialization is not a constant expression since the violation of [expr.const] p5 > an operation that would have undefined behavior as specified in [intro] through [cpp]; However, GCC accepts this example without any diagnosis.
next reply other threads:[~2022-07-14 12:15 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-14 12:15 xmh970252187 at gmail dot com [this message] 2022-07-15 21:52 ` [Bug c++/106294] " 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-106294-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).