From 9560e149b5b20138ffd3cd6ca24e8c33a68f5f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20M=C3=BCller?= <> Date: Fri, 22 Sep 2023 08:54:48 +0200 Subject: [PATCH] gtestutils.h: Fix warning with -Wsign-conversion caused by g_assert_cmpint With gcc and clang using -Wsign-conversion a related warning is generated if code using glib 2.78.0 contains function g_assert_cmpint(). Warning is fixed by adding related casts. Related tests have been also updated and will be also compiled with -Wsign-conversion to detect related problems in future. --- glib/gtestutils.h | 2 +- glib/tests/meson.build | 7 +++++++ glib/tests/testing.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 688f2eae7..30ede2588 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -54,7 +54,7 @@ typedef void (*GTestFixtureFunc) (gpointer fixture, gint64 __n1 = (n1), __n2 = (n2); \ if (__n1 cmp __n2) ; else \ g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ - #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \ + #n1 " " #cmp " " #n2, (guint64)__n1, #cmp, (guint64)__n2, 'i'); \ } G_STMT_END #define g_assert_cmpuint(n1, cmp, n2) G_STMT_START { \ guint64 __n1 = (n1), __n2 = (n2); \ diff --git a/glib/tests/meson.build b/glib/tests/meson.build index f74bacd20..d80c86efe 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -138,6 +138,13 @@ glib_tests = { 'args': [ '--verbose' ], 'extra_programs' : ['testing-helper'], }, + 'testing-macro' : { + 'args': [ '--verbose' ], + 'extra_programs' : ['testing-helper'], + 'source' : 'testing.c', + 'c_args' : cc.get_id() == 'gcc' ? ['-Werror=sign-conversion'] : [], + 'install' : false, + }, 'test-printf' : {}, 'thread' : {}, 'thread-deprecated' : {}, diff --git a/glib/tests/testing.c b/glib/tests/testing.c index e7baf7ca2..acbc1be22 100644 --- a/glib/tests/testing.c +++ b/glib/tests/testing.c @@ -486,7 +486,7 @@ test_random_conversions (void) int vint = g_test_rand_int(); char *err, *str = g_strdup_printf ("%d", vint); gint64 vint64 = g_ascii_strtoll (str, &err, 10); - g_assert_cmphex (vint, ==, vint64); + g_assert_cmpint (vint, ==, vint64); g_assert_true (!err || *err == 0); g_free (str); }