This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 07/15] Fix warning in function-tests.c
- From: David Malcolm <dmalcolm at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Bernd Schmidt <bschmidt at redhat dot com>, Jeff Law <law at redhat dot com>, David Malcolm <dmalcolm at redhat dot com>
- Date: Thu, 19 Nov 2015 12:04:51 -0500
- Subject: [PATCH 07/15] Fix warning in function-tests.c
- Authentication-results: sourceware.org; auth=none
- References: <564A1DAB dot 1030700 at redhat dot com> <1447952699-40820-1-git-send-email-dmalcolm at redhat dot com>
Upon porting from gtest.h to selftest.h I ran into this warning which
is fatal during bootstrap:
In file included from ../../../src/gcc/toplev.c:89:0:
../../../src/gcc/function-tests.c: In member function âvirtual void {anonymous}::function_test_fndecl_int_void::run()â:
../../../src/gcc/selftest.h:182:28: error: comparison with string literal results in unspecified behaviour [-Werror=address]
if ((EXPECTED) != (ACTUAL)) \
^
../../../src/gcc/function-tests.c:125:3: note: in expansion of macro âEXPECT_NEâ
EXPECT_NE ("test_fndecl_int_void", identifier_ptr);
^~~~~~~~~
../../../src/gcc/function-tests.c: In member function âvirtual void {anonymous}::function_test_fndecl_float_intchar::run()â:
../../../src/gcc/selftest.h:182:28: error: comparison with string literal results in unspecified behaviour [-Werror=address]
if ((EXPECTED) != (ACTUAL)) \
^
../../../src/gcc/function-tests.c:159:3: note: in expansion of macro âEXPECT_NEâ
EXPECT_NE ("test_fndecl_float_intchar", identifier_ptr);
^~~~~~~~~
This patch fixes the warning.
gcc/ChangeLog:
* function-tests.c (function_test, fndecl_int_void):
Introduce local "name" to avoid a "comparison with string literal"
warning.
(function_test, fndecl_float_intchar): Likewise.
---
gcc/function-tests.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/gcc/function-tests.c b/gcc/function-tests.c
index 58b27b8..db105bf 100644
--- a/gcc/function-tests.c
+++ b/gcc/function-tests.c
@@ -111,8 +111,9 @@ class function_test : public ::selftest::test
TEST_F (function_test, fndecl_int_void)
{
auto_vec <tree> param_types;
+ const char *name = "test_fndecl_int_void";
tree fndecl = make_fndecl (integer_type_node,
- "test_fndecl_int_void",
+ name,
param_types);
ASSERT_TRUE (fndecl != NULL);
@@ -122,7 +123,7 @@ TEST_F (function_test, fndecl_int_void)
EXPECT_EQ (IDENTIFIER_NODE, TREE_CODE (declname));
/* We expect it to use a *copy* of the string we passed in. */
const char *identifier_ptr = IDENTIFIER_POINTER (declname);
- EXPECT_NE ("test_fndecl_int_void", identifier_ptr);
+ EXPECT_NE (name, identifier_ptr);
EXPECT_EQ (0, strcmp ("test_fndecl_int_void", identifier_ptr));
/* Verify type of fndecl. */
@@ -145,8 +146,9 @@ TEST_F (function_test, fndecl_float_intchar)
auto_vec <tree> param_types;
param_types.safe_push (integer_type_node);
param_types.safe_push (char_type_node);
+ const char *name = "test_fndecl_float_intchar";
tree fndecl = make_fndecl (float_type_node,
- "test_fndecl_float_intchar",
+ name,
param_types);
ASSERT_TRUE (fndecl != NULL);
@@ -156,8 +158,8 @@ TEST_F (function_test, fndecl_float_intchar)
EXPECT_EQ (IDENTIFIER_NODE, TREE_CODE (declname));
/* We expect it to use a *copy* of the string we passed in. */
const char *identifier_ptr = IDENTIFIER_POINTER (declname);
- EXPECT_NE ("test_fndecl_float_intchar", identifier_ptr);
- EXPECT_EQ (0, strcmp ("test_fndecl_float_intchar", identifier_ptr));
+ EXPECT_NE (name, identifier_ptr);
+ EXPECT_EQ (0, strcmp (name, identifier_ptr));
/* Verify type of fndecl. */
EXPECT_EQ (FUNCTION_DECL, TREE_CODE (fndecl));
--
1.8.5.3