Fix "'operator new' should not return NULL" errors in testsuite
authorGary Benson <gbenson@redhat.com>
Thu, 28 May 2020 13:18:36 +0000 (14:18 +0100)
committerGary Benson <gbenson@redhat.com>
Thu, 28 May 2020 13:18:36 +0000 (14:18 +0100)
When running the testsuite with clang, gdb.linespec/cpls-ops.cc
fails to compile with the following errors:
  warning: 'operator new' should not return a null pointer unless
    it is declared 'throw()' or 'noexcept' [-Wnew-returns-null]
  warning: 'operator new[]' should not return a null pointer unless
    it is declared 'throw()' or 'noexcept' [-Wnew-returns-null]

This prevents the gdb.linespec/cpls-ops.exp testcase from executing.
This commit fixes.

gdb/testsuite/ChangeLog:

* gdb.linespec/cpls-ops.cc (dummy): New static global.
(test_op_new::operator new): Add return statement.
(test_op_new_array::operator new[]): Likewise.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.linespec/cpls-ops.cc

index 41224f9db29230311c7e5c62a48c0b55b71e2e55..d5554430bf5df24eb0770107f370947ed7352df5 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-28  Gary Benson <gbenson@redhat.com>
+
+       * gdb.linespec/cpls-ops.cc (dummy): New static global.
+       (test_op_new::operator new): Add return statement.
+       (test_op_new_array::operator new[]): Likewise.
+
 2020-05-27  Pedro Alves  <palves@redhat.com>
 
        * gdb.linespec/cp-completion-aliases.exp: Remove readline_is_used
index 283e188e6c7bdf9a7fbbf6eadf24b56bc7a03549..e9dce59e153ba776cb28fef6bb58c2c5d37bb232 100644 (file)
@@ -91,6 +91,8 @@ test_op_array::operator[] (T *t)
 
 /* Code for operator new tests.  */
 
+static int dummy;
+
 struct test_op_new
 {
   void *operator new (size_t);
@@ -99,7 +101,7 @@ struct test_op_new
 void *
 test_op_new::operator new (size_t)
 {
-  return NULL;
+  return &dummy;
 }
 
 /* Code for operator delete tests.  */
@@ -124,7 +126,7 @@ struct test_op_new_array
 void *
 test_op_new_array::operator new[] (size_t)
 {
-  return NULL;
+  return &dummy;
 }
 
 /* Code for operator delete[] tests.  */
This page took 0.029846 seconds and 4 git commands to generate.