[PATCH 07/15] Fix warning in function-tests.c

David Malcolm dmalcolm@redhat.com
Thu Nov 19 16:46:00 GMT 2015


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



More information about the Gcc-patches mailing list