This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/82528] New: Warning for conversion from bool to enum
- From: "fw at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 12 Oct 2017 12:00:15 +0000
- Subject: [Bug c/82528] New: Warning for conversion from bool to enum
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82528
Bug ID: 82528
Summary: Warning for conversion from bool to enum
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: fw at gcc dot gnu.org
Target Milestone: ---
I think this program should emit a warning in C mode:
#define TRUE ((_Bool) 1)
#define FALSE ((_Bool) 0)
typedef enum { a, b, c } result;
result
f (int flag)
{
if (flag)
return TRUE;
else
return FALSE;
}
Likewise, this should warn as well:
#include <stdbool.h>
typedef enum { a, b, c } result;
result
f (int flag)
{
if (flag)
return true;
else
return false;
}
This may require the definition of __true and __false as compiler built-ins,
similar to what exists for NULL in the C++ front end, so that the compiler can
keep up the fiction that true and false are the integer constants 1 and 0
(apparently, false is a valid NULL pointer constant, but warning about false
where NULL could be used seems reasonable to me).