Skip to content

Commit

Permalink
Merge pull request #178 from jnpkrn/format-annotations
Browse files Browse the repository at this point in the history
build: avoid too keen -Wmissing-format-attribute warning
  • Loading branch information
chrissie-c committed Feb 18, 2016
2 parents 3b7b50d + 4f6c235 commit 6137f65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions configure.ac
Expand Up @@ -489,10 +489,21 @@ for j in $WARNLIST; do
done

# warnings suppression
gcc_format_complaints=no
if test x"$GCC" = xyes && cc_supports_flag -Wmissing-format-attribute; then
gcc_format_complaints=yes
AC_DEFINE([HAVE_GCC_MISSING_FORMAT_ATTRIBUTE], [],
[gcc supports -Wmissing-format-attribute])
fi
if test x"$GCC" = xyes && cc_supports_flag -Wsuggest-attribute=format; then
gcc_format_complaints=yes
AC_DEFINE([HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT], [],
[gcc supports -Wsuggest-attribute=format])
fi
if test x"$gcc_format_complaints" = xyes; then
AC_DEFINE([HAVE_GCC_FORMAT_COMPLAINTS], [],
[gcc can complain about missing format attribute])
fi

# --- coverage ---
if test "x${enable_coverage}" = xyes && \
Expand Down
9 changes: 7 additions & 2 deletions lib/log.c
Expand Up @@ -172,12 +172,17 @@ _cs_matches_filter_(struct qb_log_callsite *cs,
* @param[in] cs Callsite containing format to use
* @param[in] ap Variable arguments for format
*/
#ifdef HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT
/* suppress suggestion that we currently can do nothing better about
as the format specification is hidden in cs argument */
#ifdef HAVE_GCC_FORMAT_COMPLAINTS
#pragma GCC diagnostic push
#ifdef HAVE_GCC_MISSING_FORMAT_ATTRIBUTE
#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
#endif
#ifdef HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT
#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
#endif
#endif
static inline void
cs_format(char *str, struct qb_log_callsite *cs, va_list ap)
{
Expand All @@ -194,7 +199,7 @@ cs_format(char *str, struct qb_log_callsite *cs, va_list ap)
str[len - 1] = '\0';
}
}
#ifdef HAVE_GCC_SUGGEST_ATTRIBUTE_FORMAT
#ifdef HAVE_GCC_FORMAT_COMPLAINTS
#pragma GCC diagnostic pop
#endif

Expand Down

0 comments on commit 6137f65

Please sign in to comment.