public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mfarazma.ext at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97266] New: "enum constant in boolean context" warning seems incorrect Date: Thu, 01 Oct 2020 18:22:12 +0000 [thread overview] Message-ID: <bug-97266-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97266 Bug ID: 97266 Summary: "enum constant in boolean context" warning seems incorrect Product: gcc Version: 8.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mfarazma.ext at gmail dot com Target Milestone: --- ``` #include <iostream> enum ValidateFlag : int8_t { a = 0, b , c }; int main(){ bool t = static_cast<bool>(c); return static_cast<int>(t); } ``` Compiling the above code with `g++ -Wall test.cc` generates this warning: warning: enum constant in boolean context [-Wint-in-bool-context] The behaviour doesn't seem correct as `c` is just an `int8_t` value, and casting an `int8_t` value to `bool` does not generate any warnings: ``` int8_t c = 2; bool t = static_cast<bool>(c); return static_cast<int>(t); ``` Having only 2 values in the enum also makes it compile fine: ``` enum ValidateFlag : int8_t { a = 0, c }; ```
next reply other threads:[~2020-10-01 18:22 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-10-01 18:22 mfarazma.ext at gmail dot com [this message] 2020-10-01 19:08 ` [Bug c++/97266] " redi at gcc dot gnu.org 2020-10-01 19:16 ` mfarazma.ext at gmail dot com 2020-10-01 22:47 ` redi at gcc dot gnu.org 2020-10-01 23:10 ` mfarazma.ext at gmail dot com 2020-10-02 13:31 ` redi at gcc dot gnu.org 2020-10-02 13:53 ` mfarazma.ext at gmail dot com
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-97266-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).