This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/16631] Problems inlining with enums
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jul 2004 18:03:45 -0000
- Subject: [Bug middle-end/16631] Problems inlining with enums
- References: <20040719172622.16631.roger@eyesopen.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From bangerth at dealii dot org 2004-07-19 18:03 -------
Take this:
-------------------------
void dummy (int);
typedef struct {
unsigned int i : 2;
} uint_2;
typedef enum E {
e_min = 0,
e_max = 4
} E;
int bar (E e) {
switch(e) {
case e_max: return 0;
}
return 1;
}
void foo (uint_2 *p) {
E e = (E) p->i;
dummy (bar (e));
}
----------------------------
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/gcc -O3 -c x.c
x.c: In function `foo':
x.c:13: warning: case label value 4 exceeds maximum value for type
Clearly, the value 4 is within the range of possible values for type 'E'.
I get the impression that gcc tries to propagate possible value ranges
from the original variable 'p->i' because of the struct is defined as
typedef struct {
unsigned int i : 3;
} uint_2;
(and should then be named uint_3), then the bug goes away. Thinking about
it, the warning even makes some sense: in a two-bit integer, even if
unsigned, the only values accessible are 0...3, so given the way we
call bar(), the case will never be triggered. How much sense it makes
to print a warning based on the fact that we can determine value ranges
for a particular call is a separate matter, though. (It parallels the
question whether we should print warnings for instantiations of C++
templates that are triggered for a particular value of the template
argument.)
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16631