libstdc++/2302: Problems with toupper

schmid@snake.iap.physik.tu-darmstadt.de schmid@snake.iap.physik.tu-darmstadt.de
Fri Mar 16 07:36:00 GMT 2001


>Number:         2302
>Category:       libstdc++
>Synopsis:       Problems with toupper
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 16 07:36:02 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Peter Schmid
>Release:        3.1 20010315 (experimental)
>Organization:
TU Darmstadt
>Environment:
System: Linux kiste 2.4.2 #34 Sun Feb 25 20:03:34 CET 2001 i686 unknown
Architecture: i686
SuSE 7.1
Glibc 2.2
GNU ld version 2.11.90.0.1 (with BFD 2.11.90.0.1)
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77,objc
>Description:
According to the book "The C++ Standard Library" by Josuttis, the call 
std::toupper(c, getloc()) is equivalent to
std::use_facet<std::ctype<char> >(getloc()).toupper(c), but this is
not the case for libstdc++-v3. If toupper(c, getloc()) is called,
the program ttoup runs without output. If
std::use_facet<std::ctype<char> >(getloc()).toupper(c) is used, the
output is correct but the conversion of the characters to
uppercase does not take place. IMHO both function calls should yield
the same results. 

>How-To-Repeat:
Source file ttoup.C

#include <iostream>
#include <streambuf>
#include <locale>
#include <cstdio>

struct outbuf : public std::streambuf
{
    virtual int_type overflow (int_type c)
        {
        if (c != traits_type::eof())
        {

//does not work at all (characters are discarded).           
//            c = std::toupper(c, getloc());

//does work but does not convert.            

            std::use_facet<std::ctype<char> >(getloc()).toupper(c);
            
            if (putchar(c) == EOF) {
                return traits_type::eof();
            }
        }
        return c;
    }
};

int main()
{
    outbuf ob;                
    std::ostream out(&ob);    

    out << "hello world!"<< std::endl;
}

Compiling the programm 
g++ -v -o ttoup ttoup.C -W -Wall
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs
Configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77,objc
gcc version 3.1 20010315 (experimental)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__STDC_HOSTED__=1 -W -Wall -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ ttoup.C -D__GNUG__=3 -D_GNU_SOURCE -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase ttoup.C -W -Wall -version -o /tmp/ccqAIahY.s
GNU CPP version 3.1 20010315 (experimental) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.1 20010315 (experimental) (i686-pc-linux-gnu)
	compiled by GNU C version 3.1 20010315 (experimental).
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++-v3
 /usr/local/include/g++-v3/i686-pc-linux-gnu
 /usr/local/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/include
 /usr/local/i686-pc-linux-gnu/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../../../i686-pc-linux-gnu/bin/as -V -Qy -o /tmp/ccIu1CVH.o /tmp/ccqAIahY.s
GNU assembler version 2.11.90.0.1 (i686-pc-linux-gnu) using BFD version 2.11.90.0.1
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o ttoup /usr/lib/crt1.o /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/crtbegin.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../../../i686-pc-linux-gnu/lib -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../.. /tmp/ccIu1CVH.o -lstdc++ -lm -lgcc_s -lc -lgcc_s /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/crtend.o /usr/lib/crtn.o

Running the programm ttoup
std::use_facet<std::ctype<char> >(getloc()).toupper(c);
peter@kiste:~ > ./ttoup
hello world!
peter@kiste:~ >

std::toupper(c, getloc());
peter@kiste:~ > ./ttoup
peter@kiste:~ >  
>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list