rengolin/HPCC-Platform — comment on commit 401809a89818be04d0710e6b6bf717b2b602cf3c
File:  line 0
By rengolin:

Sorry, you are right, ```ThrowStringException``` is a function, that is used by the macro ```throwError```.

This function is not different to any variadic function per se, what is different is the format attribute, that asks GCC to validate the parameters as it validates ```printf```-like functions.

__attribute__((format(printf, 2, 3))

This means that, ```ThrowStringException``` is a function, like ```printf```, which format string is on position 2 and has 3 parameters (ie. one item).

The problem is that macro ```throwError``` has several variants, differing in number of arguments (not variadic), using ```ThrowStringException``` with different number of parameters, which generates warnings from the ```format``` attribute validation.

This is the piece of code:

#define throwError(x) ThrowStringException(x, (x ## _Text))
#define throwError1(x,a) ThrowStringException(x, (x ## _Text), a)
#define throwError2(x,a,b) ThrowStringException(x, (x ## _Text), a, b)
#define throwError3(x,a,b,c) ThrowStringException(x, (x ## _Text), a, b, c)
#define throwError4(x,a,b,c,d) ThrowStringException(x, (x ## _Text), a, b, c, d)

This is the format attribute, on ```format (archetype, string-index, first-to-check)``` section:

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

Changing the number of parameters to zero forces GCC to ignore the number of parameters passed (ie. true variadic), but still check the format string for consistency.

If ```throwError``` had only numbered variants (1-4), this warning would not show, but it has the ```throwError(x)``` variant, to which there is no first argument.

I tried to fix this by creating a bogus argument, but that only generated other warnings because the format string had no arguments in itself, something like:

#define throwError(x) ThrowStringException(x, (x ## _Text), 0)