win32: avoid printf format warnings on nonstandard formats
authorDan Winship <danw@gnome.org>
Sun, 11 Nov 2012 16:29:16 +0000 (11:29 -0500)
committerDan Winship <danw@gnome.org>
Thu, 15 Nov 2012 19:19:06 +0000 (14:19 -0500)
glib/tests/test-printf tests some non-standard printf formats on
Windows, which gcc doesn't recognize, and so complains about. Disable
those warnings for that test.

https://bugzilla.gnome.org/show_bug.cgi?id=688109

glib/tests/test-printf.c

index 7f48b9e..10d0a1d 100644 (file)
@@ -721,6 +721,15 @@ test_64bit (void)
    * GLib 2.2, so it's best if it continues to work.
    */
 
+  /* However, gcc doesn't know about this, so we need to disable printf
+   * format warnings...
+   */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+_Pragma ("GCC diagnostic push")
+_Pragma ("GCC diagnostic ignored \"-Wformat\"")
+_Pragma ("GCC diagnostic ignored \"-Wformat-extra-args\"")
+#endif
+
   res = g_snprintf (buf, 128, "%" "lli", (gint64)123456);
   g_assert_cmpint (res, ==, 6);
   g_assert_cmpstr (buf, ==, "123456");
@@ -752,6 +761,11 @@ test_64bit (void)
   res = g_snprintf (buf, 128, "%" "ll" "X", (gint64)123456);
   g_assert_cmpint (res, ==, 5);
   g_assert_cmpstr (buf, ==, "1E240");
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+_Pragma ("GCC diagnostic pop")
+#endif
+
 #endif
 }
 
@@ -840,6 +854,15 @@ test_64bit2 (void)
    * GLib 2.2, so it's best if it continues to work.
    */
 
+  /* However, gcc doesn't know about this, so we need to disable printf
+   * format warnings...
+   */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+_Pragma ("GCC diagnostic push")
+_Pragma ("GCC diagnostic ignored \"-Wformat\"")
+_Pragma ("GCC diagnostic ignored \"-Wformat-extra-args\"")
+#endif
+
   if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT))
     {
       res = g_printf ("%" "lli", (gint64)123456);
@@ -911,6 +934,11 @@ test_64bit2 (void)
     }
   g_test_trap_assert_passed ();
   g_test_trap_assert_stdout ("*1E240*");
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+_Pragma ("GCC diagnostic pop")
+#endif
+
 #endif
 }