public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97266] New: "enum constant in boolean context" warning seems incorrect
@ 2020-10-01 18:22 mfarazma.ext at gmail dot com
  2020-10-01 19:08 ` [Bug c++/97266] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: mfarazma.ext at gmail dot com @ 2020-10-01 18:22 UTC (permalink / raw)
  To: gcc-bugs

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
};
```

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-10-02 13:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 18:22 [Bug c++/97266] New: "enum constant in boolean context" warning seems incorrect 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
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

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).