Since we have added format string attributes in the tap.h file, we get
these diagnostics on Windows:
CC test_bitfield.o
test_bitfield.c: In function 'run_test_unsigned_write':
test_bitfield.c:51:36: error: unknown conversion type character 'l' in format [-Werror=format=]
51 | #define DIAG_FMT_STR(val_type_fmt) "Failed reading value written \"%s\"-wise, with start=%i" \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_bitfield.c:51:36: note: in definition of macro 'DIAG_FMT_STR'
51 | #define DIAG_FMT_STR(val_type_fmt) "Failed reading value written \"%s\"-wise, with start=%i" \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_bitfield.c:173:8: note: in expansion of macro 'check_result'
173 | if (check_result(src_ui, readval, target.c, unsigned char,
| ^~~~~~~~~~~~
test_bitfield.c:175:9: note: format string is defined here
175 | "%llX")) {
| ^
By default, printf on Windows doesn't know about the `ll` format string
length modifier (as in %llx). However, we build Babeltrace with the
__USE_MINGW_ANSI_STDIO macro defined, which makes mingw use a
replacement printf implementation that knows about `ll`.
When we define our own functions with a format attribute, we must then
use __MINGW_PRINTF_FORMAT instead of `printf`. __MINGW_PRINTF_FORMAT
will take the right value, depending on __USE_MINGW_ANSI_STDIO, so it
will validate the format string according to the selected printf
implementation.
Change-Id: I89b194e915250a0e0a617817a1cd10fedb156639
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2161
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
#define skip_end() } while(0);
#define skip_end() } while(0);
-__attribute__((format(printf, 5, 6)))
+#ifdef __MINGW_PRINTF_FORMAT
+# define PRINT_FORMAT __MINGW_PRINTF_FORMAT
+#else
+# define PRINT_FORMAT printf
+#endif
+
+__attribute__((format(PRINT_FORMAT, 5, 6)))
unsigned int _gen_result(int, const char *, const char *, unsigned int, const char *, ...);
int plan_no_plan(void);
int plan_skip_all(const char *);
int plan_tests(unsigned int);
unsigned int _gen_result(int, const char *, const char *, unsigned int, const char *, ...);
int plan_no_plan(void);
int plan_skip_all(const char *);
int plan_tests(unsigned int);
-__attribute__((format(printf, 1, 2)))
+__attribute__((format(PRINT_FORMAT, 1, 2)))
unsigned int diag(const char *, ...);
void diag_multiline(const char *);
unsigned int diag(const char *, ...);
void diag_multiline(const char *);
-__attribute__((format(printf, 2, 3)))
+__attribute__((format(PRINT_FORMAT, 2, 3)))
int skip(unsigned int, const char *, ...);
int skip(unsigned int, const char *, ...);
-__attribute__((format(printf, 1, 2)))
+__attribute__((format(PRINT_FORMAT, 1, 2)))
void todo_start(const char *, ...);
void todo_end(void);
void todo_start(const char *, ...);
void todo_end(void);