From: brarcher Date: Sat, 7 Dec 2013 05:05:15 +0000 (+0000) Subject: fix ck_assert_ptr_* causing const compilation warnings X-Git-Tag: 0.10.0~355 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e93752dacf7e5406712a64606d0e53489270450f;p=check fix ck_assert_ptr_* causing const compilation warnings A test sequence such as: const struct my_vtable expected_element; struct my_vtable* test_element; ck_assert_ptr_eq(test_element, &expected_element); Compiled using gcc 4.7.2 with -Wall gives the following warning. myfile.c:70:2: warning: initialization discards ‘const’ qualifier from pointer target type [enabled by default] Adding a const qualifier to the variables in the _ck_assert_ptr macro, as done for _ck_assert_str makes the problem go away. Issue #91, patch submitted by user lordlod24. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@861 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/AUTHORS b/AUTHORS index ff78f54..b3efa7f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,6 +42,7 @@ Contributors: Martin Willers (rename check's internal list API to start with check_) bross (patches for msys/mingw32 support) Pino Toscano (GNU/Hurd support for subsecond timeouts) + lod (compiler warning) Anybody who has contributed code to Check or Check's build system is considered an author. Send patches to this file to diff --git a/NEWS b/NEWS index 41be5e0..8d85406 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ In development: - +* fix ck_assert_ptr_* causing const compilation warnings. Patch from + bug #91. Wed, Nov 4, 2013: Released Check 0.9.11 based on r856 (2013-11-04 02:09:21 +0000) diff --git a/src/check.h.in b/src/check.h.in index 3604098..3d886ae 100644 --- a/src/check.h.in +++ b/src/check.h.in @@ -328,8 +328,8 @@ void CK_EXPORT _ck_assert_msg (int result, const char *file, /* Pointer comparsion macros with improved output compared to ck_assert(). */ /* OP may only be == or != */ #define _ck_assert_ptr(X, OP, Y) do { \ - void* _ck_x = (X); \ - void* _ck_y = (Y); \ + const void* _ck_x = (X); \ + const void* _ck_y = (Y); \ ck_assert_msg(_ck_x OP _ck_y, "Assertion '"#X#OP#Y"' failed: "#X"==%#x, "#Y"==%#x", _ck_x, _ck_y); \ } while (0) #define ck_assert_ptr_eq(X, Y) _ck_assert_ptr(X, ==, Y)