]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/util/testsuite_hooks.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_hooks.cc
index b5249f449405778497e65942988ee51ec543ad1f..559d2583d841ff759642c16524bf818b01ae9446 100644 (file)
@@ -1,14 +1,13 @@
 // -*- C++ -*-
 
-// Utility subroutines for the C++ library testsuite. 
+// Utility subroutines for the C++ library testsuite.
 //
-// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
-// Free Software Foundation, Inc.
+// Copyright (C) 2002-2024 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 // terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
 // any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // GNU General Public License for more details.
 //
 // You should have received a copy of the GNU General Public License along
-// with this library; see the file COPYING.  If not, write to the Free
-// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
 //
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
 
 #include <testsuite_hooks.h>
 
@@ -41,7 +31,6 @@
 #include <list>
 #include <string>
 #include <stdexcept>
-#include <cstddef>
 #include <clocale>
 #include <cstdlib>
 #include <locale>
@@ -64,7 +53,7 @@
 namespace __gnu_test
 {
 #ifdef _GLIBCXX_RES_LIMITS
-  void 
+  void
   set_memory_limits(float size)
   {
     struct rlimit r;
@@ -116,10 +105,10 @@ namespace __gnu_test
 #else
   void
   set_memory_limits(float) { }
-#endif 
+#endif
 
 #ifdef _GLIBCXX_RES_LIMITS
-  void 
+  void
   set_file_limit(unsigned long size)
   {
 #if _GLIBCXX_HAVE_LIMIT_FSIZE
@@ -136,14 +125,17 @@ namespace __gnu_test
 #else
   void
   set_file_limit(unsigned long) { }
-#endif 
+#endif
 
-  void 
+  void
   verify_demangle(const char* mangled, const char* wanted)
   {
     int status = 0;
-    const char* s = abi::__cxa_demangle(mangled, 0, 0, &status);
-    if (!s)
+    const char* s = 0;
+    char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
+    if (demangled)
+      s = demangled;
+    else
       {
        switch (status)
          {
@@ -167,26 +159,26 @@ namespace __gnu_test
     std::string w(wanted);
     if (w != s)
       std::__throw_runtime_error(s);
+    free(demangled);
   }
 
-  void 
+  void
   run_tests_wrapped_locale(const char* name, const func_callback& l)
   {
     using namespace std;
-    bool test = true;
-    
-    // Set the global locale. 
+
+    // Set the global locale.
     locale loc_name = locale(name);
     locale orig = locale::global(loc_name);
 
     const char* res = setlocale(LC_ALL, name);
-    if (res != NULL)
+    if (res)
       {
        string preLC_ALL = res;
        const func_callback::test_type* tests = l.tests();
        for (int i = 0; i < l.size(); ++i)
          (*tests[i])();
-       string postLC_ALL= setlocale(LC_ALL, NULL);
+       string postLC_ALL= setlocale(LC_ALL, 0);
        VERIFY( preLC_ALL == postLC_ALL );
       }
     else
@@ -196,20 +188,19 @@ namespace __gnu_test
        __throw_runtime_error(s.c_str());
       }
   }
-  
-  void 
+
+  void
   run_tests_wrapped_env(const char* name, const char* env,
                        const func_callback& l)
   {
     using namespace std;
-    bool test = true;
-    
-#ifdef _GLIBCXX_HAVE_SETENV 
-    // Set the global locale. 
+
+#ifdef _GLIBCXX_HAVE_SETENV
+    // Set the global locale.
     locale loc_name = locale(name);
     locale orig = locale::global(loc_name);
 
-    // Set environment variable env to value in name. 
+    // Set environment variable env to value in name.
     const char* oldENV = getenv(env);
     if (!setenv(env, name, 1))
       {
@@ -228,7 +219,7 @@ namespace __gnu_test
 #endif
   }
 
-  counter::size_type  counter::count = 0;
+  object_counter::size_type  object_counter::count = 0;
   unsigned int copy_constructor::count_ = 0;
   unsigned int copy_constructor::throw_on_ = 0;
   unsigned int assignment_operator::count_ = 0;
@@ -239,7 +230,7 @@ namespace __gnu_test
 #ifdef _GLIBCXX_SYSV_SEM
   // This union is not declared in system headers.  Instead, it must
   // be defined by user programs.
-  union semun 
+  union semun
   {
     int val;
     struct semid_ds *buf;
@@ -247,10 +238,10 @@ namespace __gnu_test
   };
 #endif
 
-  semaphore::semaphore() 
+  semaphore::semaphore()
   {
 #ifdef _GLIBCXX_SYSV_SEM
-    // Remeber the PID for the process that created the semaphore set
+    // Remember the PID for the process that created the semaphore set
     // so that only one process will destroy the set.
     pid_ = getpid();
 
@@ -258,7 +249,7 @@ namespace __gnu_test
 #ifndef SEM_R
 #define SEM_R 0400
 #endif
-    
+
 #ifndef SEM_A
 #define SEM_A 0200
 #endif
@@ -281,21 +272,22 @@ namespace __gnu_test
 #endif
   }
 
-  semaphore::~semaphore() 
+  semaphore::~semaphore()
   {
 #ifdef _GLIBCXX_SYSV_SEM
     union semun val;
-    // Destroy the semaphore set only in the process that created it. 
+    val.val = 0; // Avoid uninitialized variable warning.
+    // Destroy the semaphore set only in the process that created it.
     if (pid_ == getpid())
       semctl(sem_set_, 0, IPC_RMID, val);
 #endif
   }
 
   void
-  semaphore::signal() 
+  semaphore::signal()
   {
 #ifdef _GLIBCXX_SYSV_SEM
-    struct sembuf op[1] = 
+    struct sembuf op[1] =
       {
        { 0, 1, 0 }
       };
@@ -305,16 +297,16 @@ namespace __gnu_test
   }
 
   void
-  semaphore::wait() 
+  semaphore::wait()
   {
 #ifdef _GLIBCXX_SYSV_SEM
-    struct sembuf op[1] = 
+    struct sembuf op[1] =
       {
        { 0, -1, SEM_UNDO }
       };
     if (semop(sem_set_, op, 1) == -1)
       std::__throw_runtime_error("could not wait for semaphore");
-#endif    
+#endif
   }
 
   // For use in 22_locale/time_get and time_put.