Software Environment:
Linux 2.6.9-5.EL #1 SMP Wed Jan 5 19:23:58 EST 2005 ppc64 ppc64 ppc64
GNU/Linux
gcc version 3.4.3 20041212
(**but seems to be in 3.4.4 and 4.0 code too).
Steps to Reproduce:
1. Source File:
t.C
---
#include <locale>
class myctype : public std::ctype<char>
{
protected:
const char* do_narrow(const char* lo, const char* hi, char dflt, char* to)
const
{
for (int i=0;lo!=hi;++lo,++to,++i)
{
*to=*lo+i;
}
return hi;
}
};
int main()
{
myctype mc;
const char input [] = "abcd";
const char input1 [] = "abcd";
char tmp[sizeof(input)] = {0};
char tmp1[sizeof(input1)]= {0};
mc.narrow(input, input + sizeof(input), '*', tmp);
printf("tmp is: %s\n",tmp);
mc.narrow(input1, input1 + sizeof(input1), '*', tmp1);
printf("tmp1 is: %s\n",tmp1);
return 0;
}
-----------------------------------------------------------
2. Execute command:
/usr/bin/g++ t.C
a.out
Actual Results:
tmp is: aceg
tmp1 is: abcd
Expected Results:
tmp is: aceg
tmp1 is: aceg
-------------------------------------------------------
This change in behavior seems to have come in via this patch:
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg01106.html
,with the changes to locale_facet2.h
Now, there is a protected _M_narrow_ok member that seems to control whether that
memcpy path should be taken. Maybe the logic for setting _M_narrow_ok needs a
fixing. The memcpy path should only be taken when it is discovered that the
narrowing operation does not do anything. Otherwise, it should use the
narrowing cache (or just call do_narrow())
--
Summary: Second std::ctype<char>::narrow() does not call
std::ctype<char>::do_narrow()
Product: gcc
Version: 3.4.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jgrimm2 at us dot ibm dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19955