Skip to content

Commit 5ded807

Browse files
fingolfingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a469a10 commit 5ded807

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ extern int check_repository_format_version(const char *var, const char *value, v
11361136
extern int git_env_bool(const char *, int);
11371137
extern int git_config_system(void);
11381138
extern int config_error_nonbool(const char *);
1139-
#ifdef __GNUC__
1139+
#if defined(__GNUC__) && ! defined(__clang__)
11401140
#define config_error_nonbool(s) (config_error_nonbool(s), -1)
11411141
#endif
11421142
extern const char *get_log_output_encoding(void);

git-compat-util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
295295
* behavior. But since we're only trying to help gcc, anyway, it's OK; other
296296
* compilers will fall back to using the function as usual.
297297
*/
298-
#ifdef __GNUC__
298+
#if defined(__GNUC__) && ! defined(__clang__)
299299
#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
300300
#endif
301301

parse-options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extern NORETURN void usage_msg_opt(const char *msg,
177177

178178
extern int optbug(const struct option *opt, const char *reason);
179179
extern int opterror(const struct option *opt, const char *reason, int flags);
180-
#ifdef __GNUC__
180+
#if defined(__GNUC__) && ! defined(clang)
181181
#define opterror(o,r,f) (opterror((o),(r),(f)), -1)
182182
#endif
183183

0 commit comments

Comments
 (0)