This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: wrong warning w/ non-void functions
- To: Ingolf Koch <ingolf at minet dot uni-jena dot de>
- Subject: Re: wrong warning w/ non-void functions
- From: Jim Wilson <wilson at cygnus dot com>
- Date: Wed, 18 Mar 1998 16:13:13 -0800
- cc: egcs-bugs at cygnus dot com
enum ab {A, B};
int f(ab argument) {
switch (argument) {
case A: return 1;
case B: return 2;
}
}
Current versions of the compiler warn about
"control reaches end of non-void function `f(ab)'"
when compiling with -Wall.
The warning is correct for C. The parameter `argument' can have any value
from 0 to INT_MAX, so there is a path through the function that that not
return a value. In C, variables with enum type are not restricted to values
defined in the enum.
C++ has different rules for enums than C, so I am unsure whether the same
is true for C++.
If a warning is indeed desired in this case, it would be
nice to have an option to suppress it (if -Wall is specified).
This would be reasonable.
Jim