From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
David Aguilar <davvid@gmail.com>,
Ramsay Jones <ramsay@ramsayjones.plus.com>,
GIT Mailing-list <git@vger.kernel.org>
Subject: Re: Fixing the warning about warning(""); was: Re: [PATCH] difftool.c: mark a file-local symbol with static
Date: Wed, 25 Jan 2017 17:01:01 -0500 [thread overview]
Message-ID: <20170125220101.et67ebkumsqosaku@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq7f5iakxw.fsf@gitster.mtv.corp.google.com>
On Wed, Jan 25, 2017 at 01:28:27PM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > The only advantage is that it is self-documenting, so somebody does not
> > come through later and convert ("%s", "") back to (""). We could also
> > write a comment. But I am happy if we simply catch it in review (or
> > preferably the person is clueful enough to read the output of git-blame
> > and see why it is that way in the first place).
>
> And the last sentence unfortunatly does not reflect reality.
>
> I would prefer something self-documenting, like your wrapper with a
> comment. Then somebody who is looking at the implementation of
> warning_blank_line() will not get tempted to turn "%s", "" into ""
> because of the comment. And somebody who is looking at the callsite
> of warning_blank_line() will think twice before suggesting to turn
> it into warning("").
I am OK with it either way. I was mostly responding to Dscho's
complaint, and I would just like to get this resolved so we never have
to revisit it again. :)
> In any case, the patch is a minimum effort band-aid that lets us
> punt on the whole issue for now, so I'll queue it as-is.
Here's one other option that I came across. Pragmas feel gross, but I
think it will behave as we want, and it doesn't require cooperation from
the callsites at all.
-- >8 --
Subject: [PATCH] disable -Wzero-length-format via #pragma
Building with "gcc -Wall" will complain that the format in:
warning("")
is empty. Which is true, but the warning is over-eager. We
are calling the function for its side effect of printing
"warning:", even with an empty string.
We disable this warning already with the DEVELOPER Makefile
knob. But we can't unconditionally add -Wno-format-zero-length
to the normal CFLAGS variable, because not all compilers will
understand it. So we may get reports about the warning from
non-developer users who compile with our default of -Wall.
Instead, we can disable the warning using a gcc-specific
#pragma. This should be ignored by non-gcc compilers, and do
what we want for gcc.
I tested also with clang, which often implements gcc
compatible extensions like this. Clang does not generate the
warning in the first place, but also does not complain about
our pragma.
Signed-off-by: Jeff King <peff@peff.net>
---
git-compat-util.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/git-compat-util.h b/git-compat-util.h
index 325950426..a6558930d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -413,6 +413,8 @@ extern int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2
extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
extern void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
+#pragma GCC diagnostic ignored "-Wformat-zero-length"
+
#ifndef NO_OPENSSL
#ifdef APPLE_COMMON_CRYPTO
#include "compat/apple-common-crypto.h"
--
2.11.0.840.gd37c5973a
next prev parent reply other threads:[~2017-01-25 22:01 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-29 17:36 [PATCH] difftool.c: mark a file-local symbol with static Ramsay Jones
2016-11-30 11:07 ` Johannes Schindelin
2016-11-30 19:57 ` Ramsay Jones
2016-11-30 20:40 ` Junio C Hamano
2016-11-30 21:25 ` Jeff King
2016-11-30 22:37 ` Ramsay Jones
2016-11-30 23:18 ` Jeff King
2016-11-30 23:46 ` Junio C Hamano
2016-12-01 1:18 ` Ramsay Jones
2016-12-01 4:02 ` Jeff King
2016-12-01 18:20 ` Junio C Hamano
2016-12-01 18:50 ` Jeff King
2017-01-22 5:26 ` David Aguilar
2017-01-24 14:23 ` Jeff King
2017-01-24 21:52 ` Junio C Hamano
2017-01-24 23:05 ` Jeff King
2017-01-25 10:36 ` Fixing the warning about warning(""); was: " Johannes Schindelin
2017-01-25 18:35 ` Jeff King
2017-01-25 21:28 ` Junio C Hamano
2017-01-25 22:01 ` Jeff King [this message]
2017-01-26 6:39 ` Johannes Sixt
2017-01-26 11:37 ` Johannes Schindelin
2017-01-26 14:35 ` Jeff King
2017-01-26 14:32 ` Jeff King
2017-01-26 18:26 ` Junio C Hamano
2017-01-26 11:16 ` Johannes Schindelin
2017-01-26 14:39 ` Jeff King
2017-01-26 14:49 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170125220101.et67ebkumsqosaku@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Johannes.Schindelin@gmx.de \
--cc=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ramsay@ramsayjones.plus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).