This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/15276] New: Erroneous Comparisons of Negative Characters
- From: "mckelvey at maskull dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 May 2004 04:51:39 -0000
- Subject: [Bug libstdc++/15276] New: Erroneous Comparisons of Negative Characters
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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.
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.
Result of running test program, with my analysis:
122 Expected character value of 'z'.
-64 Expected value of signed character '\0300'
192 Expected value of unsigned character '\0300'
-64 Shows that chars are signed
SC 1 Expected character comparison as signed char
UC 0 Expected character comparison as unsigned char
CH 1 Expected character comparison as char (signed)
SV 1 Demonstrates that std::string::value_type is signed
ST 0 Error: std::string of length 1 does not compare the same as CH
BS 1 std::basic_string<signed char> compares as expected
BU 0 std::basic_string<unsigned char> compares as expected
BC 0 Error: Same as ST, as expected (std::basic_string<char>)
TS 1 std::char_traits<signed char> compares signed char * as expected
TU 0 std::char_traits<signed char> compares unsigned char * as expected
TC 0 Error: std::char_traits<char>, char * does not compare properly
LS 1 std::char_traits<signed char> compares signed char as expected
LU 0 std::char_traits<unsigned char> compares unsigned char as expected
LC 1 std::char_traits<char> compares char as expected
(Note: inconsistent with TC)
MC 0 std::memcmp is comparing as unsigned (I guess that's OK)
SC 0 Error: std::strcmp is comparing as unsigned
SN 0 Error: std::strncmp is comparing as unsigned
SL 0 Error: std::strcoll is comparing as unsigned
--
Summary: Erroneous Comparisons of Negative Characters
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mckelvey at maskull dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: alphaev56-unknown-linux-gnu
GCC host triplet: alphaev56-unknown-linux-gnu
GCC target triplet: alphaev56-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15276