[libvirt] [PATCH] Conditionalize use of -Wno-suggest-attribute=format pragma

Daniel P. Berrange berrange at redhat.com
Fri Jan 16 14:55:22 UTC 2015


Many GCC versions don't understand -Wno-suggest-attribute=format
so the pragma must only be used when supported
---
 m4/virt-compile-warnings.m4 | 6 ++++++
 src/internal.h              | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 532a777..b412a42 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -215,6 +215,12 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
         ;;
     esac
 
+    case $WARN_CFLAGS in
+        *-Wsuggest-attribute=format*)
+           AC_DEFINE(HAVE_SUGGEST_ATTRIBUTE_FORMAT, [1], [Whether -Wsuggest-attribute=format works])
+        ;;
+    esac
+
     # Silence certain warnings in gnulib, and use improved glibc headers
     AC_DEFINE([lint], [1],
       [Define to 1 if the compiler is checking for lint.])
diff --git a/src/internal.h b/src/internal.h
index 9855c49..4d473af 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -234,9 +234,15 @@
 #  define VIR_WARNINGS_NO_CAST_ALIGN \
     _Pragma ("GCC diagnostic push") \
     _Pragma ("GCC diagnostic ignored \"-Wcast-align\"")
-#  define VIR_WARNINGS_NO_PRINTF \
+
+#  if HAVE_SUGGEST_ATTRIBUTE_FORMAT
+#   define VIR_WARNINGS_NO_PRINTF \
     _Pragma ("GCC diagnostic push") \
     _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=format\"")
+#  else
+#   define VIR_WARNINGS_NO_PRINTF \
+    _Pragma ("GCC diagnostic push")
+#  endif
 
 #  define VIR_WARNINGS_RESET \
     _Pragma ("GCC diagnostic pop")
-- 
2.1.0




More information about the libvir-list mailing list