[gnu.gcc.bug] gcc warning: empty body in else-statement

edler@JAN.ULTRA.NYU.EDU (Jan Edler) (01/09/90)

(I'm using the NYU internal version of gcc for the ibm rt pc, if it matters).

If I compile with -Wall, I get warnings about else statements with
empty bodies, e.g.

	if (expr)
		f();
	else	;

In my case the empty body is generated by a macro.

1) These warnings don't seem very useful to me; am I missing something?
   Is there a common error that will be caught by the warning?

2) Is there a way to turn them off, and still keep -Wall?

3) I can suppress them by using a null inline function, like

	static inline void null() { }

   and change my macro to evaluate to null(); is there a better way?


Jan Edler
NYU Ultracomputer Research Laboratory
edler@nyu.edu

ado@elsie.UUCP (Arthur David Olson) (01/09/90)

> If I compile with -Wall, I get warnings about else statements with
> empty bodies, e.g.
> 
> 	if (expr)
> 		f();
> 	else	;
> 
> ...These warnings don't seem very useful to me; am I missing something?
> Is there a common error that will be caught by the warning?

The "common" error caught by the code generating the above message is...
	if (expression);
		statement;
...where the extra semicolon at the end of the first line results in
"statement" being executed unconditionally.  The "else" case is designed to
guard against the less-common...
	if (expression);
		statement;
	else; if (expression2)
		statement2;
	else	statement3;

On the system here at least, you can eliminate the warning by having the
macro generate code in the form...
	if (expr)
		f();
	else	{}
-- 
		1972:  Canada has no Saturn V equivalent
		1990:  Canada has no Saturn V equivalent
	Arthur David Olson   ado@alw.nih.gov   ADO is a trademark of Ampex.