check gcc version before using gnu_printf attribute
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 15 Nov 2020 08:15:13 +0000 (09:15 +0100)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 15 Nov 2020 08:15:13 +0000 (09:15 +0100)
The MacOS clang compiler does not know the gnu_printf attribute.
gnu_printf was introduced with gcc version 4.4 so I check the
gcc version before using gnu_printf. Otherwise I fallback to the
previous __printf__ attribute.

src/libpspp/compiler.h
src/output/pivot-table.h

index fb85a553e7f6930fcc56a66859869858aa9f03fd..6ce8f1aecb41f89e94f48ca3a0b03b9db42f68cc 100644 (file)
 /* Mark a function as taking a printf- or scanf-like format
    string as its FMT'th argument and that the FIRST'th argument
    is the first one to be checked against the format string. */
+#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4)
 #define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (gnu_printf, FMT, FIRST)))
+#else
+#define PRINTF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (__printf__, FMT, FIRST)))
+#endif
 #define SCANF_FORMAT(FMT, FIRST) ATTRIBUTE ((format (__scanf__, FMT, FIRST)))
 
 /* Tells the compiler that a function may be treated as if any
index cc61377fc29818160b438e8866ca001873d51af0..99fbdb295df000b4cfb50b05dcd084eb2478efd8 100644 (file)
@@ -706,7 +706,11 @@ struct pivot_value *pivot_value_new_variable (const struct variable *);
 /* Values from text strings. */
 struct pivot_value *pivot_value_new_text (const char *);
 struct pivot_value *pivot_value_new_text_format (const char *, ...)
+#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__>= 4) || __GNUC__ > 4)
   __attribute__((format(gnu_printf, 1, 2)));
+#else
+  __attribute__((format(__printf__, 1, 2)));
+#endif
 
 struct pivot_value *pivot_value_new_user_text (const char *, size_t length);
 struct pivot_value *pivot_value_new_user_text_nocopy (char *);