[PATCH] warning: suggest braces around empty body in an 'else' statement

Started by Andres Freundover 12 years ago2 messageshackers
Jump to latest
#1Andres Freund
andres@anarazel.de

Hi,

Compiling postgres I currently get the following warning when compiling
without LOCK_DEBUG:
/home/andres/src/postgresql/src/backend/storage/lmgr/lock.c:944:52:
warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
PROCLOCK_PRINT("LockAcquire: NOWAIT", proclock);

It'd be easy to just disable the warning with -Wno-empty-body, but I actually like
the warning.

It's easy to fix by defining PROCLOCK_PRINT to (void)0 instead of
defining it empty when LOCK_DEBUG is enabled.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

fix-suggest-braces-empty-body-warning.difftext/x-diff; charset=us-asciiDownload+2-2
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#1)
Re: [PATCH] warning: suggest braces around empty body in an 'else' statement

Andres Freund <andres@2ndquadrant.com> writes:

Compiling postgres I currently get the following warning when compiling
without LOCK_DEBUG:
/home/andres/src/postgresql/src/backend/storage/lmgr/lock.c:944:52:
warning: suggest braces around empty body in an 'else' statement [-Wempty-body]
PROCLOCK_PRINT("LockAcquire: NOWAIT", proclock);

It'd be easy to just disable the warning with -Wno-empty-body, but I actually like
the warning.

It's easy to fix by defining PROCLOCK_PRINT to (void)0 instead of
defining it empty when LOCK_DEBUG is enabled.

Seems reasonable, and probably a good policy even without compiler
warnings pushing us to do it --- things that look like functions
should expand to expressions, IMO, not empty.

Committed with some extra parentheses just for luck.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers