From: Jeff King <peff@peff.net>
To: Max Horn <max@quendi.de>
Cc: John Keeping <john@keeping.me.uk>,
Antoine Pelisse <apelisse@gmail.com>,
Junio C Hamano <gitster@pobox.com>, git <git@vger.kernel.org>,
Johannes Sixt <j6t@kdbg.org>
Subject: Re: [PATCH] fix some clang warnings
Date: Wed, 16 Jan 2013 10:09:29 -0800 [thread overview]
Message-ID: <20130116180929.GD27525@sigill.intra.peff.net> (raw)
In-Reply-To: <20130116180041.GC27525@sigill.intra.peff.net>
On Wed, Jan 16, 2013 at 10:00:42AM -0800, Jeff King wrote:
> So opterror does not happen to generate any warnings, because we do not
> ever use it in a void context. It should probably be marked the same
> way, though, as future-proofing.
> [...]
> So a more accurate description would be:
Here it is all together:
-- >8 --
From: Max Horn <max@quendi.de>
Subject: [PATCH] fix clang -Wunused-value warnings for error functions
Commit a469a10 wraps some error calls in macros to give the
compiler a chance to do more static analysis on their
constant -1 return value. We limit the use of these macros
to __GNUC__, since gcc is the primary beneficiary of the new
information, and because we use GNU features for handling
variadic macros.
However, clang also defines __GNUC__, but generates warnings
with -Wunused-value when these macros are used in a void
context, because the constant "-1" ends up being useless.
Gcc does not complain about this case (though it is unclear
if it is because it is smart enough to see what we are
doing, or too dumb to realize that the -1 is unused). We
can squelch the warning by just disabling these macros when
clang is in use.
Signed-off-by: Max Horn <max@quendi.de>
Signed-off-by: Jeff King <peff@peff.net>
---
cache.h | 2 +-
git-compat-util.h | 2 +-
parse-options.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index c257953..5c8440b 100644
--- a/cache.h
+++ b/cache.h
@@ -1148,7 +1148,7 @@ extern int config_error_nonbool(const char *);
extern int git_env_bool(const char *, int);
extern int git_config_system(void);
extern int config_error_nonbool(const char *);
-#ifdef __GNUC__
+#if defined(__GNUC__) && ! defined(__clang__)
#define config_error_nonbool(s) (config_error_nonbool(s), -1)
#endif
extern const char *get_log_output_encoding(void);
diff --git a/git-compat-util.h b/git-compat-util.h
index 2cecf56..2596280 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -297,7 +297,7 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
* behavior. But since we're only trying to help gcc, anyway, it's OK; other
* compilers will fall back to using the function as usual.
*/
-#ifdef __GNUC__
+#if defined(__GNUC__) && ! defined(__clang__)
#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
#endif
diff --git a/parse-options.h b/parse-options.h
index e703853..1c8bd8d 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -177,7 +177,7 @@ extern int opterror(const struct option *opt, const char *reason, int flags);
extern int optbug(const struct option *opt, const char *reason);
extern int opterror(const struct option *opt, const char *reason, int flags);
-#ifdef __GNUC__
+#if defined(__GNUC__) && ! defined(clang)
#define opterror(o,r,f) (opterror((o),(r),(f)), -1)
#endif
--
1.8.1.rc1.10.g7d71f7b
next prev parent reply other threads:[~2013-01-16 18:09 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 14:53 [PATCH] fix some clang warnings Max Horn
2013-01-16 16:04 ` Jeff King
2013-01-16 16:53 ` Junio C Hamano
2013-01-16 17:12 ` Antoine Pelisse
2013-01-16 17:18 ` John Keeping
2013-01-16 17:26 ` Max Horn
2013-01-16 17:50 ` Jeff King
2013-01-16 18:00 ` Jeff King
2013-01-16 18:09 ` Jeff King [this message]
2013-01-16 18:12 ` John Keeping
2013-01-16 18:15 ` Jeff King
2013-01-16 18:21 ` Antoine Pelisse
2013-01-16 18:22 ` John Keeping
2013-01-16 18:24 ` Jeff King
2013-01-16 19:01 ` John Keeping
2013-01-17 10:24 ` John Keeping
2013-01-16 22:47 ` [PATCH 1/2] fix clang -Wconstant-conversion with bit fields Antoine Pelisse
2013-01-16 22:47 ` [PATCH 2/2] fix clang -Wtautological-compare with unsigned enum Antoine Pelisse
2013-01-16 23:10 ` Antoine Pelisse
2013-01-17 10:32 ` Antoine Pelisse
2013-01-17 11:00 ` John Keeping
2013-01-17 11:23 ` [PATCH] combine-diff: suppress a clang warning John Keeping
2013-01-17 16:44 ` [PATCH 2/2] fix clang -Wtautological-compare with unsigned enum Linus Torvalds
2013-01-17 16:56 ` Antoine Pelisse
2013-01-17 17:02 ` John Keeping
2013-01-18 17:15 ` Phil Hord
2013-01-18 18:52 ` Linus Torvalds
2013-01-16 23:08 ` [PATCH 1/2] fix clang -Wconstant-conversion with bit fields John Keeping
2013-01-16 23:09 ` Antoine Pelisse
2013-01-16 23:15 ` Antoine Pelisse
2013-01-16 23:43 ` Junio C Hamano
2013-01-16 23:46 ` Junio C Hamano
2013-01-16 18:03 ` [PATCH] fix some clang warnings Tomas Carnecky
2013-01-16 18:12 ` Matthieu Moy
2013-02-01 5:37 ` Miles Bader
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=20130116180929.GD27525@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=apelisse@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=john@keeping.me.uk \
--cc=max@quendi.de \
/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).