autoconf: check for format __attribute__ to avoid warnings 56/12956/6
authorMichael Meffie <mmeffie@sinenomine.net>
Sun, 14 Jan 2018 14:38:26 +0000 (09:38 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 10 Aug 2018 11:55:08 +0000 (07:55 -0400)
Building with Solaris Studio generates a ludicrous number of warnings
in the form:

   roken.h, line ...: warning: attribute "format" is unknown, ignored

Modern Solaris Studio supports several GCC-style function attributes,
including the `noreturn' attribute, however does not support the
`format' attribute.

Currently, configure defines HAVE___ATTRIBUTE__ when the `noreturn'
attribute is available. roken headers conditionally declare printf-like
functions with the `format' function attribute when HAVE___ATTRIBUTE__
is defined, leading to the warning messages when building under Solaris
Studio. Unsupported function attributes generate warnings, not errors.

Fix these warnings by defining HAVE___ATTRIBUTE__ if and only if the
`format' attribute is supported by the compiler, instead of checking for
`noreturn'.  Note that the `format' type is currently the only attribute
used by roken at this time.

Change-Id: I569167333d65df2583befc19befa8d719b93d75a
Reviewed-on: https://gerrit.openafs.org/12956
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/cf/c-attribute.m4

index c179d90..be339a8 100644 (file)
@@ -1,27 +1,17 @@
 dnl
-dnl $Id$
+dnl GCC-style function __attribute__ checks.
 dnl
-
-dnl
-dnl Test for __attribute__
+dnl Define HAVE___ATTRIBUTE__ if and only if we specifically support the
+dnl `format' function attribute. This is done for the imported roken
+dnl headers, which use that symbol to conditionally declare functions with
+dnl printf-like arguments. This is the only use of function attributes in
+dnl roken.  The HAVE___ATTRIBUTE__ symbol is not used in the OpenAFS code.
 dnl
-
 AC_DEFUN([OPENAFS_C_ATTRIBUTE], [
-AC_MSG_CHECKING(for __attribute__)
-AC_CACHE_VAL(ac_cv___attribute__, [
-AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
-static void foo(void) __attribute__ ((noreturn));
+  AX_GCC_FUNC_ATTRIBUTE([format])
 
-static void
-foo(void)
-{
-  exit(1);
-}
-]])],
-[ac_cv___attribute__=yes],
-[ac_cv___attribute__=no])])
-if test "$ac_cv___attribute__" = "yes"; then
-  AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
-fi
-AC_MSG_RESULT($ac_cv___attribute__)
+  AS_IF([test "$ax_cv_have_func_attribute_format" = "yes"], [
+    AC_DEFINE([HAVE___ATTRIBUTE__], [1],
+      [define if your compiler has __attribute__((format))])
+  ])
 ])