# [PATCH] Use __VA_ARGS__ for all of error's arguments

9 messages from 2013-02-07 to 2013-02-08. Participants: Matt Kraai, Junio C Hamano, John Keeping, Jeff King.
Thread: https://gitlist.dev/t/32851

## Matt Kraai, 2013-02-07 20:00

Subject: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <1360267238-21896-1-git-send-email-kraai@ftbfs.org>
URL: https://gitlist.dev/e/1360267238-21896-1-git-send-email-kraai%40ftbfs.org

```
From: Matt Kraai <matt.kraai@amo.abbott.com>

QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
comma if the error macro's variable argument is left out.

Instead of testing for a sufficiently recent version of GCC, make
__VA_ARGS__ match all of the arguments.  Since this should work on any
C99-compliant compiler, also remove the tests around the macro definition.

Signed-off-by: Matt Kraai <matt.kraai@amo.abbott.com>
---
 git-compat-util.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..df1681f 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -305,14 +305,9 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 /*
  * Let callers be aware of the constant return value; this can help
- * gcc with -Wuninitialized analysis. We have to restrict this trick to
- * gcc, though, because of the variadic macro and the magic ## comma pasting
- * 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.
+ * gcc with -Wuninitialized analysis.
  */
-#if defined(__GNUC__) && ! defined(__clang__)
-#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
-#endif
+#define error(...) (error(__VA_ARGS__), -1)
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
 extern void set_error_routine(void (*routine)(const char *err, va_list params));
-- 
1.8.1.GIT

```

## Junio C Hamano, 2013-02-07 21:05

Subject: Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <7vwquj6dio.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwquj6dio.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1360267238-21896-1-git-send-email-kraai@ftbfs.org>

```
Matt Kraai <kraai@ftbfs.org> writes:

> -#if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> -#endif
> +#define error(...) (error(__VA_ARGS__), -1)

Before your change, we only define error() macro for GCC variants,
but with your patch that no longer is the case.  Does every compiler
that compiles Git correctly today support this style of varargs
macros?

```

## John Keeping, 2013-02-07 21:14

Subject: Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <20130207211449.GC1342@serenity.lan>
URL: https://gitlist.dev/e/20130207211449.GC1342%40serenity.lan
In-Reply-To: <7vwquj6dio.fsf@alter.siamese.dyndns.org>

```
On Thu, Feb 07, 2013 at 01:05:19PM -0800, Junio C Hamano wrote:
> Matt Kraai <kraai@ftbfs.org> writes:
> 
> > -#if defined(__GNUC__) && ! defined(__clang__)
> > -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> > -#endif
> > +#define error(...) (error(__VA_ARGS__), -1)
> 
> Before your change, we only define error() macro for GCC variants,
> but with your patch that no longer is the case.  Does every compiler
> that compiles Git correctly today support this style of varargs
> macros?

At the very least the "! defined(__clang__)" was only recently added
[1], although it shouldn't be needed once Clang 3.3 is released.

[1] http://article.gmane.org/gmane.comp.version-control.git/213787


John

```

## Matt Kraai, 2013-02-07 21:24

Subject: Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <20130207212438.GA22253@ftbfs.org>
URL: https://gitlist.dev/e/20130207212438.GA22253%40ftbfs.org
In-Reply-To: <7vwquj6dio.fsf@alter.siamese.dyndns.org>

```
On Thu, Feb 07, 2013 at 01:05:19PM -0800, Junio C Hamano wrote:
> Matt Kraai <kraai@ftbfs.org> writes:
> 
> > -#if defined(__GNUC__) && ! defined(__clang__)
> > -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> > -#endif
> > +#define error(...) (error(__VA_ARGS__), -1)
> 
> Before your change, we only define error() macro for GCC variants,
> but with your patch that no longer is the case.  Does every compiler
> that compiles Git correctly today support this style of varargs
> macros?

I don't know and I don't think it's likely I can confirm this.  I'll
submit a new patch that just changes the definition, since I don't
know of any problems other than mine with the current situation.

-- 
Matt

```

## Matt Kraai, 2013-02-07 21:30

Subject: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <1360272632-22566-1-git-send-email-kraai@ftbfs.org>
URL: https://gitlist.dev/e/1360272632-22566-1-git-send-email-kraai%40ftbfs.org
In-Reply-To: <20130207212438.GA22253@ftbfs.org>

```
From: Matt Kraai <matt.kraai@amo.abbott.com>

QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
comma if the error macro's variable argument is left out.

Instead of testing for a sufficiently recent version of GCC, make
__VA_ARGS__ match all of the arguments.

Signed-off-by: Matt Kraai <matt.kraai@amo.abbott.com>
---
 git-compat-util.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..2e960a9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -305,13 +305,10 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 /*
  * Let callers be aware of the constant return value; this can help
- * gcc with -Wuninitialized analysis. We have to restrict this trick to
- * gcc, though, because of the variadic macro and the magic ## comma pasting
- * 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.
+ * gcc with -Wuninitialized analysis.
  */
 #if defined(__GNUC__) && ! defined(__clang__)
-#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
+#define error(...) (error(__VA_ARGS__), -1)
 #endif
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
-- 
1.8.1.2.546.gfc9f004

```

## Jeff King, 2013-02-08 04:24

Subject: Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <20130208042428.GA4157@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20130208042428.GA4157%40sigill.intra.peff.net
In-Reply-To: <1360272632-22566-1-git-send-email-kraai@ftbfs.org>

```
On Thu, Feb 07, 2013 at 01:30:32PM -0800, Matt Kraai wrote:

> From: Matt Kraai <matt.kraai@amo.abbott.com>
> 
> QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
> comma if the error macro's variable argument is left out.
> 
> Instead of testing for a sufficiently recent version of GCC, make
> __VA_ARGS__ match all of the arguments.

Thanks, this looks better than the original (we do not assume a C99
compiler, so just doing this unconditionally would probably break some
other older systems which do not use gcc).

>  /*
>   * Let callers be aware of the constant return value; this can help
> - * gcc with -Wuninitialized analysis. We have to restrict this trick to
> - * gcc, though, because of the variadic macro and the magic ## comma pasting
> - * 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.
> + * gcc with -Wuninitialized analysis.
>   */
>  #if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> +#define error(...) (error(__VA_ARGS__), -1)

Should you be dropping most of the comment like this? I would expect it
to be more like:

  We have to restrict this trick to gcc, though, because we do not
  assume all compilers support variadic macros. But since...

Other than that, I think it is OK. The compiler will still catch
"error()" with no arguments and generate the appropriate diagnostic (in
fact, it is better, because the error is now passing too few args to a
function, not to the macro).

-Peff

```

## Matt Kraai, 2013-02-08 04:39

Subject: Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <20130208043915.GB4525@ftbfs.org>
URL: https://gitlist.dev/e/20130208043915.GB4525%40ftbfs.org
In-Reply-To: <20130208042428.GA4157@sigill.intra.peff.net>

```
On Thu, Feb 07, 2013 at 11:24:28PM -0500, Jeff King wrote:
> Should you be dropping most of the comment like this? I would expect it
> to be more like:
> 
>   We have to restrict this trick to gcc, though, because we do not
>   assume all compilers support variadic macros. But since...

I'll submit a new patch with this change tomorrow.

> Other than that, I think it is OK. The compiler will still catch
> "error()" with no arguments and generate the appropriate diagnostic (in
> fact, it is better, because the error is now passing too few args to a
> function, not to the macro).

Great, thanks for the review.

-- 
Matt

```

## Matt Kraai, 2013-02-08 15:09

Subject: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <1360336168-27740-1-git-send-email-kraai@ftbfs.org>
URL: https://gitlist.dev/e/1360336168-27740-1-git-send-email-kraai%40ftbfs.org
In-Reply-To: <20130208043915.GB4525@ftbfs.org>

```
From: Matt Kraai <matt.kraai@amo.abbott.com>

QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
comma if the error macro's variable argument is left out.

Instead of testing for a sufficiently recent version of GCC, make
__VA_ARGS__ match all of the arguments.

Signed-off-by: Matt Kraai <matt.kraai@amo.abbott.com>
---
 git-compat-util.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..b7eaaa9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -305,13 +305,13 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 /*
  * Let callers be aware of the constant return value; this can help
- * gcc with -Wuninitialized analysis. We have to restrict this trick to
- * gcc, though, because of the variadic macro and the magic ## comma pasting
- * 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.
+ * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,
+ * because some compilers may not support variadic macros. Since we're only
+ * trying to help gcc, anyway, it's OK; other compilers will fall back to
+ * using the function as usual.
  */
 #if defined(__GNUC__) && ! defined(__clang__)
-#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
+#define error(...) (error(__VA_ARGS__), -1)
 #endif
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
-- 
1.8.1.2.546.g90a97a4

```

## Jeff King, 2013-02-08 15:54

Subject: Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
Message-ID: <20130208155416.GA20874@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20130208155416.GA20874%40sigill.intra.peff.net
In-Reply-To: <1360336168-27740-1-git-send-email-kraai@ftbfs.org>

```
On Fri, Feb 08, 2013 at 07:09:28AM -0800, Matt Kraai wrote:

> From: Matt Kraai <matt.kraai@amo.abbott.com>
> 
> QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
> comma if the error macro's variable argument is left out.
> 
> Instead of testing for a sufficiently recent version of GCC, make
> __VA_ARGS__ match all of the arguments.
>
> [...]
>
>  /*
>   * Let callers be aware of the constant return value; this can help
> - * gcc with -Wuninitialized analysis. We have to restrict this trick to
> - * gcc, though, because of the variadic macro and the magic ## comma pasting
> - * 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.
> + * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,
> + * because some compilers may not support variadic macros. Since we're only
> + * trying to help gcc, anyway, it's OK; other compilers will fall back to
> + * using the function as usual.
>   */
>  #if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> +#define error(...) (error(__VA_ARGS__), -1)

Acked-by: Jeff King <peff@peff.net>

Thanks.

-Peff

```
