[PATCH] Add warning_decl and error_decl attributes

Jakub Jelinek jakub@redhat.com
Mon Sep 10 15:56:00 GMT 2007


On Mon, Sep 10, 2007 at 07:07:42AM -0700, Andrew Pinski wrote:
> On 9/10/07, Jakub Jelinek <jakub@redhat.com> wrote:
> > warning_decl is similar to error_decl, but it prints a warning
> > instead of error.  It is useful e.g. for glibc swapped memset arguments
> > warning.  Currently glibc uses
> > __warndecl (__warn_memset_zero_len,
> >             "memset used with constant zero length parameter; this could be due to transposed parameters");
> 
> Except I will make a mention, it is wrong for glibc (or GCC) warning
> about this.
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16794

You only get the warning if you compile with -D_FORTIFY_SOURCE=2,
which is documented to impose limitations beyond the standards
(unlike -D_FORTIFY_SOURCE=1), like e.g. %n not being allowed
for *printf if the format string is writeable etc.
It is just a warning, and while you can write it intentionally
that way, it is far more probably just an unintended mistake
(it discovered many such problems in the past already) and
there is very little justification to obfuscate your code that way.
If you want to evaluate side-effects of the second argument, you
can certainly do so as part of a comma expression.

	Jakub



More information about the Gcc-patches mailing list