]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/util/testsuite_character.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / testsuite_character.h
index 547775bd8864155eb8573a61d05e8c87cc495da8..115430a99da1119f9501e6256024377d8681f91e 100644 (file)
@@ -3,12 +3,12 @@
 // Testing character type and state type with char_traits and codecvt
 // specializations for the C++ library testsuite.
 //
-// Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+// Copyright (C) 2003-2020 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.
 
 #ifndef _GLIBCXX_TESTSUITE_CHARACTER_H
 #define _GLIBCXX_TESTSUITE_CHARACTER_H
 #include <ext/pod_char_traits.h>
 
 namespace __gnu_test
-{  
+{
   struct pod_int
   {
     int value;
+
+#if __cplusplus >= 201103L
+    // For std::iota.
+    pod_int&
+    operator++()
+    {
+      ++value;
+      return *this;
+    }
+#endif
   };
-  
+
+  // For 20.1 requirements for instantiable type: equality comparable
+  // and less than comparable.
   inline bool
   operator==(const pod_int& lhs, const pod_int& rhs)
   { return lhs.value == rhs.value; }
-  
+
   inline bool
   operator<(const pod_int& lhs, const pod_int& rhs)
   { return lhs.value < rhs.value; }
 
+  // For 26 numeric algorithms requirements, need addable,
+  // subtractable, multiplicable.
+  inline pod_int
+  operator+(const pod_int& lhs, const pod_int& rhs)
+  {
+    pod_int ret = { lhs.value + rhs.value };
+    return ret;
+  }
+
+  inline pod_int
+  operator-(const pod_int& lhs, const pod_int& rhs)
+  {
+    pod_int ret = { lhs.value - rhs.value };
+    return ret;
+  }
+
+  inline pod_int
+  operator*(const pod_int& lhs, const pod_int& rhs)
+  {
+    pod_int ret = { lhs.value * rhs.value };
+    return ret;
+  }
+
   struct pod_state
   {
     unsigned long value;
@@ -72,10 +98,10 @@ namespace __gnu_test
   typedef character<unsigned char, pod_int, pod_state>         pod_char;
   typedef character<unsigned char, unsigned int, pod_state>    pod_uchar;
   typedef character<unsigned short, unsigned int>              pod_ushort;
-  typedef character<unsigned int, unsigned long>               pod_uint;  
+  typedef character<unsigned int, unsigned long>               pod_uint;
 }
 
-namespace __gnu_cxx 
+namespace __gnu_cxx
 {
   // Specializations.
   // pod_char
@@ -96,7 +122,7 @@ namespace __gnu_cxx
        V2 ret = { c.value };
        return ret;
       }
-  
+
   template<>
     template<typename V2>
       inline __gnu_test::pod_uchar::char_type
@@ -112,7 +138,7 @@ namespace __gnu_cxx
       inline V2
       __gnu_test::pod_uchar::char_type::to(const char_type& c)
       { return static_cast<V2>(c.value << 5); }
-}; // namespace __gnu_test
+} // namespace __gnu_test
 
 namespace std
 {
@@ -134,7 +160,7 @@ namespace std
   // 3. tmp becomes the new value of state.
   template<>
     class codecvt<__gnu_test::pod_uchar, char, __gnu_test::pod_state>
-    : public __codecvt_abstract_base<__gnu_test::pod_uchar, char, 
+    : public __codecvt_abstract_base<__gnu_test::pod_uchar, char,
                                     __gnu_test::pod_state>
     {
     public:
@@ -267,7 +293,7 @@ namespace std
                const extern_type* end, size_t max) const
       {
        const extern_type* beg = from;
-       while (from < end && max)
+       while (from < end)
          {
            unsigned char c = *from;
            if (c & 0xc0)
@@ -278,6 +304,8 @@ namespace std
                continue;
              }
 
+           if (max == 0) break;
+
            unsigned char tmp;
            if (state.value & 0x8)
              {
@@ -362,7 +390,7 @@ namespace std
       do_widen(char c) const
       { return __gnu_test::pod_uchar::from<char>(c); }
 
-      virtual const char* 
+      virtual const char*
       do_widen(const char* low, const char* high, char_type* dest) const
       {
        transform(low, high, dest, &__gnu_test::pod_uchar::from<char>);
@@ -383,88 +411,88 @@ namespace std
     };
 
   // numpunct specializations
-  template<> 
+  template<>
     class numpunct<__gnu_test::pod_uint>
     : public locale::facet
-    { 
-    public: 
-      typedef __gnu_test::pod_uint    char_type; 
-      typedef basic_string<char_type> string_type; 
-    
-      static locale::id id; 
-      
+    {
+    public:
+      typedef __gnu_test::pod_uint    char_type;
+      typedef basic_string<char_type> string_type;
+
+      static locale::id id;
+
       explicit
       numpunct(size_t refs = 0)
-      : locale::facet(refs) 
-      { } 
+      : locale::facet(refs)
+      { }
+
       char_type
-      decimal_point() const 
-      { return this->do_decimal_point(); } 
+      decimal_point() const
+      { return this->do_decimal_point(); }
+
       char_type
-      thousands_sep() const 
-      { return this->do_thousands_sep(); } 
+      thousands_sep() const
+      { return this->do_thousands_sep(); }
+
       string
-      grouping() const 
-      { return this->do_grouping(); } 
+      grouping() const
+      { return this->do_grouping(); }
+
       string_type
-      truename() const 
-      { return this->do_truename(); } 
+      truename() const
+      { return this->do_truename(); }
+
       string_type
-      falsename() const 
-      { return this->do_falsename(); } 
-    protected: 
+      falsename() const
+      { return this->do_falsename(); }
+
+    protected:
       ~numpunct()
-      { } 
+      { }
+
       virtual char_type
-      do_decimal_point() const 
-      { return char_type(); } 
+      do_decimal_point() const
+      { return char_type(); }
+
       virtual char_type
-      do_thousands_sep() const 
-      { return char_type(); } 
+      do_thousands_sep() const
+      { return char_type(); }
+
       virtual string
-      do_grouping() const 
-      { return string(); } 
+      do_grouping() const
+      { return string(); }
+
       virtual string_type
-      do_truename() const 
+      do_truename() const
       { return string_type(); }
+
       virtual string_type
-      do_falsename() const 
-      { return string_type(); } 
+      do_falsename() const
+      { return string_type(); }
     };
 
-  template<> 
+  template<>
     class moneypunct<__gnu_test::pod_uint>
     : public locale::facet, public money_base
-    { 
-    public: 
-      typedef __gnu_test::pod_uint    char_type; 
-      typedef basic_string<char_type> string_type; 
-    
-      static locale::id id; 
+    {
+    public:
+      typedef __gnu_test::pod_uint    char_type;
+      typedef basic_string<char_type> string_type;
+
+      static locale::id id;
       static const bool intl = false;
 
       explicit
       moneypunct(size_t refs = 0)
-      : locale::facet(refs) 
+      : locale::facet(refs)
       { }
+
       char_type
-      decimal_point() const 
-      { return this->do_decimal_point(); } 
+      decimal_point() const
+      { return this->do_decimal_point(); }
+
       char_type
-      thousands_sep() const 
+      thousands_sep() const
       { return this->do_thousands_sep(); }
 
       string
@@ -472,17 +500,17 @@ namespace std
       { return this->do_grouping(); }
 
       string_type
-      curr_symbol() const 
-      { return this->do_curr_symbol(); } 
+      curr_symbol() const
+      { return this->do_curr_symbol(); }
+
       string_type
-      positive_sign() const 
-      { return this->do_positive_sign(); } 
+      positive_sign() const
+      { return this->do_positive_sign(); }
 
       string_type
-      negative_sign() const 
-      { return this->do_negative_sign(); } 
-      
+      negative_sign() const
+      { return this->do_negative_sign(); }
+
       int
       frac_digits() const
       { return this->do_frac_digits(); }
@@ -490,39 +518,39 @@ namespace std
       pattern
       pos_format() const
       { return this->do_pos_format(); }
+
       pattern
       neg_format() const
       { return this->do_neg_format(); }
-  
-    protected: 
-      ~moneypunct() 
-      { } 
+
+    protected:
+      ~moneypunct()
+      { }
+
       virtual char_type
-      do_decimal_point() const 
-      { return char_type(); } 
+      do_decimal_point() const
+      { return char_type(); }
+
       virtual char_type
-      do_thousands_sep() const 
-      { return char_type(); } 
+      do_thousands_sep() const
+      { return char_type(); }
+
       virtual string
-      do_grouping() const 
+      do_grouping() const
       { return string(); }
 
       virtual string_type
-      do_curr_symbol() const 
-      { return string_type(); } 
+      do_curr_symbol() const
+      { return string_type(); }
+
       string_type
-      do_positive_sign() const 
-      { return string_type(); } 
+      do_positive_sign() const
+      { return string_type(); }
 
       string_type
-      do_negative_sign() const 
-      { return string_type(); } 
-      
+      do_negative_sign() const
+      { return string_type(); }
+
       int
       do_frac_digits() const
       { return 0; }
@@ -530,7 +558,7 @@ namespace std
       pattern
       do_pos_format() const
       { return pattern(); }
+
       pattern
       do_neg_format() const
       { return pattern(); }