This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Erroneous Comparisons of Negative Characters


James W. McKelvey <mckelvey@maskull.com> writes:

> When chars are implemented as signed, characters with negative values compare 
> properly as individual chars, but improperly when part of a char array or 
> std::string -- they compare as unsigned. The problem appears to be that the 
> specialization of std::char_traits<char> uses memcmp. This is observed on an 
> Alpha running RH 7.1 and gcc version 3.5.0 20040207.

I see the same behavior with gcc 3.4.0 on i686-freeBSD5.2

> 
> Specifically, std::char_traits<char>::compare is inconsistent with 
> std::char_traits<char>::lt, which affects std::string (which is just 
> std::basic_string<char>.) The problem also affects strcmp, strncmp, and 
> strcoll.
[snip]

std::char_traits<char>::compare is defined in terms of
    std::char_traits<char>::lt in 21.1.1/1 table 37, and I can't find
    a reason why they might be allowed to be inconsistent.

I think you should report a bug, see gcc.gnu.org/bugs.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]