Re: [PATCH 2/3] git-compat: introduce BUG_ON(condition, fmt, ...) macro
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Nov 22, 2017, 23:02 UTC
- Message-ID
- <20171122230239.GG11671@aiede.mtv.corp.google.com>
- In-Reply-To
- <20171122223827.26773-3-sbeller@google.com>
Hi,
Stefan Beller wrote:
Show 14 quoted lines
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -1092,9 +1092,13 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
> __attribute__((format (printf, 3, 4))) NORETURN
> void BUG_fl(const char *file, int line, const char *fmt, ...);
> #define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)
> +#define BUG_ON(condition, ...) do { if (condition) BUG(__VA_ARGS__); } while (0)
> #else
> __attribute__((format (printf, 1, 2))) NORETURN
> void BUG(const char *fmt, ...);
> +
> +__attribute__((format (printf, 2, 3)))
> +void BUG_ON(int condition, const char *fmt, ...);
> #endifI worry that these definitions are mildly incompatible: the macro accepts anything that can go in an 'if', including pointers, and the function only accepts an int.
Is there a way for the macro to typecheck that its argument is an integer to avoid that?
Thanks, Jonathan