From: Ryan Lortie Date: Sat, 15 Feb 2014 13:44:05 +0000 (-0500) Subject: only '#pragma GCC' outside of functions X-Git-Tag: 2.39.90~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=08533cae05dfe6d3af5e02c95af9de65680cdae0;p=platform%2Fupstream%2Fglib.git only '#pragma GCC' outside of functions Don't use #pragma GCC inside of function scope. https://bugzilla.gnome.org/show_bug.cgi?id=724417 --- diff --git a/glib/tests/test-printf.c b/glib/tests/test-printf.c index e17585b..c6dd9d9 100644 --- a/glib/tests/test-printf.c +++ b/glib/tests/test-printf.c @@ -71,7 +71,6 @@ test_d (void) { gchar buf[128]; gint res; - const gchar *fmt; /* %d basic formatting */ @@ -182,14 +181,24 @@ test_d (void) res = g_snprintf (buf, 128, "%03d", -5); g_assert_cmpint (res, ==, 3); g_assert_cmpstr (buf, ==, "-05"); +} - /* gcc emits warnings for the following formats, since the C spec - * says some of the flags must be ignored. (The " " in "% +d" and - * the "0" in "%-03d".) But we need to test that our printf gets - * those rules right. So we fool gcc into not warning. - */ +/* gcc emits warnings for the following formats, since the C spec + * says some of the flags must be ignored. (The " " in "% +d" and + * the "0" in "%-03d".) But we need to test that our printf gets + * those rules right. So we fool gcc into not warning. + * + * These have to be in a separate function in order to use #pragma. + */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-nonliteral" +static void +test_d_invalid (void) +{ + const gchar *fmt; + gchar buf[128]; + gint res; + fmt = "% +d"; res = g_snprintf (buf, 128, fmt, 5); g_assert_cmpint (res, ==, 2); @@ -199,8 +208,8 @@ test_d (void) res = g_snprintf (buf, 128, fmt, -5); g_assert_cmpint (res, ==, 3); g_assert_cmpstr (buf, ==, "-5 "); -#pragma GCC diagnostic pop } +#pragma GCC diagnostic pop static void test_o (void) @@ -891,6 +900,7 @@ main (int argc, g_test_add_func ("/snprintf/retval-and-trunc", test_retval_and_trunc); g_test_add_func ("/snprintf/%d", test_d); + g_test_add_func ("/snprintf/%d-invalid", test_d_invalid); g_test_add_func ("/snprintf/%o", test_o); g_test_add_func ("/snprintf/%u", test_u); g_test_add_func ("/snprintf/%x", test_x);