Switch coverage

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Wed Dec 31 04:19:00 GMT 1997


I noticed that egcs 971225 creates new error messages:

extern inline void * __constant_memcpy(void * to, const void * from, unsigned int n)
{
	switch (n % 4) {
		case 0: return to;
		case 1: return to;
		case 2: return to;
		case 3: return to;
	}
}

mira% gcc -V egcs-2.90.21 -Wall -O2 -c warn.c
mira% gcc -V egcs-2.91.03 -Wall -O2 -c warn.c
warn.c: In function `__constant_memcpy':
warn.c:9: warning: control reaches end of non-void function

Why was this change introduced? I believe neither version was able
to detect that, for all possible values of n, control does *not*
reach end of the non-void function. So the warning is wrong, although
I can see cases where it is useful.

The older gcc versions would report the warning only if the function
was not inline. There is some value to that approach: when it is
inlined, gcc could still try to detect whether there is no result
returned. In case of this function, it would detect that there is
no problem to complain about (as n is known at compile time for
each invocation).

This code is from the Linux kernel. It would be easy to remove
the warning by adding an addition 'return to;' in the end, but
people usually hesitate introducing extra code just to avoid
bogus gcc warnings.

Regards,
Martin



More information about the Gcc mailing list