https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89450
Bug ID: 89450
Summary: RFC: Strengthen -fstrict-enums
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
Target Milestone: ---
Currently, we warn about:
$ cat /tmp/strict.cc
enum XXX
{
A,
B,
C,
D,
E
};
int foo(XXX x)
{
switch (x)
case A:
case B:
case C:
case D:
case E:
return 2;
}
int main(int argc, char **argv)
{
return foo ((XXX)argc);
}
$ g++ /tmp/strict.cc -c -fstrict-enums
/tmp/strict.cc: In function ‘int foo(XXX)’:
/tmp/strict.cc:19:1: warning: control reaches end of non-void function
[-Wreturn-type]
19 | }
| ^
Issues is that:
14746 /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */
14747 if (flag_strict_enums)
14748 set_min_and_max_values_for_integral_type (enumtype, precision,
sgn);
is called for precision, which sets min = 0 and max = 7.
What about doing:
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 612afbacd27..46302b4a61d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14745,7 +14745,10 @@ finish_enum_value_list (tree enumtype)
/* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */
if (flag_strict_enums)
- set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
+ {
+ TYPE_MIN_VALUE (enumtype) = minnode;
+ TYPE_MAX_VALUE (enumtype) = maxnode;
+ }
}
else
underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
I can also imagine another option level when desired.