[Bug libstdc++/55244] New: char_traits compares characters as though unsigned

2012-11-08 Thread GCC at DanielRHouck dot com

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

 Bug #: 55244
   Summary: char_traits compares characters as though
unsigned
Classification: Unclassified
   Product: gcc
   Version: 4.5.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: g...@danielrhouck.com


Created attachment 28641
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28641
The preprocessed source code briefly demonstrating this behavior.

According to the C++ standard, char_traits::compare's value is defined in terms
of char_traits::lt's. The unspecialized version of the char_traits template
implements this correctly. However, char_traits redefines compare based
on __builtin_memcmp, and does not work correctly for characters not in the
range [0, 127]. Specifically, it compares characters as though they were
unsigned instead of signed.

The attached preprocessed code was produced by "g++ -v -save-temps testcase.cpp
-o testcase" executed on a simple file. The output of gcc is below:
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/usr/portage-tmp/portage/sys-devel/gcc-4.5.3-r2/work/gcc-4.5.3/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --disable-lto --enable-nls
--without-included-gettext --with-system-zlib --enable-obsolete
--disable-werror --enable-secureplt --enable-multilib --enable-libmudflap
--disable-libssp --enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.3/python
--enable-checking=release --enable-java-awt=gtk
--enable-languages=c,c++,java,fortran --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all
--with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.3-r2 p1.5,
pie-0.4.7'
Thread model: posix
gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.5, pie-0.4.7) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'testcase' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/cc1plus -E -quiet -v -D_GNU_SOURCE
testcase.cpp -D_FORTIFY_SOURCE=2 -mtune=generic -march=x86-64 -fpch-preprocess
-o testcase.ii
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4/x86_64-pc-linux-gnu
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4/backward
 /usr/local/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'testcase' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/cc1plus -fpreprocessed testcase.ii
-quiet -dumpbase testcase.cpp -mtune=generic -march=x86-64 -auxbase testcase
-version -o testcase.s
GNU C++ (Gentoo 4.5.3-r2 p1.5, pie-0.4.7) version 4.5.3 (x86_64-pc-linux-gnu)
compiled by GNU C version 4.5.3, GMP version 5.0.2, MPFR version 3.0.1-p4,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Gentoo 4.5.3-r2 p1.5, pie-0.4.7) version 4.5.3 (x86_64-pc-linux-gnu)
compiled by GNU C version 4.5.3, GMP version 5.0.2, MPFR version 3.0.1-p4,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3053bf2eb42d601ba6282eebbd0ccc30
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'testcase' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/as
-V -Qy --64 -o testcase.o testcase.s
GNU assembler version 2.21.1 (x86_64-pc-linux-gnu) using BFD version (GNU
Binutils) 2.21.1
COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/:/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.3/:/usr/libexec/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x86_64-pc-linux-gnu/bin/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/../../../../x

[Bug libstdc++/55244] char_traits compares characters as though unsigned

2012-11-08 Thread GCC at DanielRHouck dot com


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



--- Comment #1 from Daniel Houck  2012-11-08 
23:19:27 UTC ---

Created attachment 28642

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28642

The original source code before preprocessing



I am including this because the problem lies with the standard library and not

the compiler, and therefore it may be useful to know exactly how I included the

standard library.