[Bug libstdc++/19955] [3.4/4.0 regression] Second std::ctype<char>::narrow() does not call std::ctype<char>::do_narrow()

jgrimm2 at us dot ibm dot com gcc-bugzilla@gcc.gnu.org
Tue Feb 15 06:41:00 GMT 2005


------- Additional Comments From jgrimm2 at us dot ibm dot com  2005-02-14 23:41 -------
Trivial patch.  Set _M_narrow_ok to 1 only when memcpy would have given the same
results as do_narrow(). 
 

Index: locale_facets.h
===================================================================
RCS file: /opt/gcc-cvs/gcc/libstdc++-v3/include/bits/locale_facets.h,v
retrieving revision 1.85.2.4.2.2
diff -c -3 -p -r1.85.2.4.2.2 locale_facets.h
*** locale_facets.h     9 Jun 2004 12:31:52 -0000       1.85.2.4.2.2
--- locale_facets.h     14 Feb 2005 20:30:27 -0000
*************** namespace std
*** 1170,1177 ****
        }

        // Fill in the narrowing cache and flag whether all values are
!       // valid or not.  _M_narrow_ok is set to 1 if the whole table is
!       // narrowed, 2 if only some values could be narrowed.
        void _M_narrow_init() const
        {
        char __tmp[sizeof(_M_narrow)];
--- 1170,1176 ----
        }

        // Fill in the narrowing cache and flag whether all values are
!       // valid or not.  _M_narrow_ok is set to 1 if memcpy can be used.
        void _M_narrow_init() const
        {
        char __tmp[sizeof(_M_narrow)];
*************** namespace std
*** 1179,1199 ****
          __tmp[__i] = __i;
        do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);

!       // Check if any default values were created.  Do this by
!       // renarrowing with a different default value and comparing.
!       bool __consecutive = true;
!       for (size_t __j = 0; __j < sizeof(_M_narrow); ++__j)
!         if (!_M_narrow[__j])
!           {
!             char __c;
!             do_narrow(__tmp + __j, __tmp + __j + 1, 1, &__c);
!             if (__c == 1)
!               {
!                 __consecutive = false;
!                 break;
!               }
!           }
!       _M_narrow_ok = __consecutive ? 1 : 2;
        }
      };

--- 1178,1188 ----
          __tmp[__i] = __i;
        do_narrow(__tmp, __tmp + sizeof(__tmp), 0, _M_narrow);

!       _M_narrow_ok = 1;
!       // Set _M_narrow_ok to 2 if memcpy can't be used.
!       if (memcmp(__tmp, _M_narrow, sizeof(_M_narrow)))
!         _M_narrow_ok = 2;
!
        }
      };





-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19955



More information about the Gcc-bugs mailing list