This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: wrong warning w/ non-void functions


	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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]