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] "enum constant in boolean context" warning seems incorrect
Date: Thu, 01 Oct 2020 19:16:42 +0000	[thread overview]
Message-ID: <bug-97266-4-3PSNmR7q1o@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97266-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97266

--- Comment #2 from m farazma <mfarazma.ext at gmail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to m farazma from comment #0)
> > ```
> > #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,
> 
> No it isn't. In C enumerators are just integers, but in C++ they have the
> same type as the enumeration type they belong to.
> 
But isn't the type of the enum set to be `int8_t` in this example?
In which case casting from `int8_t` to `bool` should be straight forward and
without warnings.

  parent reply	other threads:[~2020-10-01 19:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 18:22 [Bug c++/97266] New: " mfarazma.ext at gmail dot com
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 [this message]
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-3PSNmR7q1o@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: link
Be 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).