[Bug c/48778] gcc 4.6 -Waddress adds unhelpful new warning case when using from a macro
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Mar 1 16:25:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48778
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Peter Eisentraut from comment #0)
> I don't think this is really helpful. Macros like in the above example are
> not uncommon, and there is no obvious way to write the code better.
A better way (in that it doesn't elicit the warning) to write buflen() is as an
inline function, perhaps while leaving the buflen macro in place:
#define buflen(b) ((b) == NULL ? 0 : (b)->len)
static inline size_t (buflen)(const buf *b) { return buflen (b); }
Then users of buflen have a choice of calling either the function (by
parenthesizing the name) or the macro (without the parentheses). This practice
is codified in the C standard where C library functions may be (also) defined
as macros this way.
I would rather not compromise the GCC warning since it's possible to make the
opposite argument: that not issuing the warning for macros is unhelpful.
More information about the Gcc-bugs
mailing list