Bug 15565 - [3.4 only] SLES9: leading + sign for unsigned int with showpos
Summary: [3.4 only] SLES9: leading + sign for unsigned int with showpos
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: 3.4.1
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-21 16:57 UTC by Grigor Nikolov
Modified: 2004-10-30 21:11 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.0.4 3.2.3 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2004-05-21 17:16:24


Attachments
preprocessed file (94.00 KB, text/plain)
2004-05-21 17:00 UTC, Grigor Nikolov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Grigor Nikolov 2004-05-21 16:57:04 UTC
On SLES9 when print using iostream the value of unsigned integral type with the 
preceding use of 'showpos' format flag - shows the sign '+'. 

This is a bug in the library on SLES9

Table 60 in subclause 22.2.2.2.2 from ISO/IEC 14882:1998 C++ standard implies 
that line 1 in the example program below should have the same output behaviour 
as line 2:

#include <iostream>
#include <stdio.h>

int main() {
        std::cout << std::showpos << 42U << std::endl;  // line 1
        printf("%+u\n", 42U);  // line 2
}

The C standard says of the '+' flag character:
"The result of a signed conversion always begins with a plus or minus sign."  
Since the conversion in the example above is unsigned, the + has no effect, and 
the correct output for this program is:

42
42

  Please, tell me if you really need the preprocessed file (*.i*). It is quite 
big, when the code to reproduce the problem is small.

Source code:     t.cpp
======================================================
#include <iostream>
#include <stdio.h>

int main() {
        std::cout << std::showpos << 42U << std::endl;  // line 1
        printf("%+u\n", 42U);  // line 2
}


Script to be run to reproduce the problem
======================================================
#!/usr/bin/ksh
#
rm -f *.o t
g++ "$@" -o t t.cpp 
echo Return code: $?
t 
echo Return code: $?


Actual output is:
======================================================
Reading specs from /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-
prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --enable-
languages=c,c++,f77,objc,java,ada --disable-checking --libdir=/usr/lib --enable-
libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-
system-zlib --enable-shared --enable-__cxa_atexit --host=powerpc-suse-linux --
build=powerpc-suse-linux --target=powerpc-suse-linux --enable-targets=powerpc64-
suse-linux --enable-biarch
Thread model: posix
gcc version 3.3.3 (SuSE Linux)
 /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/cc1plus -E -D__GNUG__=3 -quiet -v -
D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 -D_GNU_SOURCE -
D__unix__ -D__gnu_linux__ -D__linux__ -Dunix -D__unix -Dlinux -D__linux -
Asystem=unix -Asystem=posix t.cpp t.ii
ignoring nonexistent directory "/usr/powerpc-suse-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/include/g++/powerpc-suse-linux
 /usr/include/g++/backward
 /usr/local/include
 /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/cc1plus -fpreprocessed t.ii -quiet -
dumpbase t.cpp -auxbase t -version -o t.s
GNU C++ version 3.3.3 (SuSE Linux) (powerpc-suse-linux)
        compiled by GNU C version 3.3.3 (SuSE Linux).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32768
 /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/../../../../powerpc-suse-
linux/bin/as -a32 -mppc -V -Qy -o t.o t.s
GNU assembler version 2.15.90.0.1.1 (powerpc-suse-linux) using BFD version 
2.15.90.0.1.1 20040303 (SuSE Linux)
 /usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/collect2 --eh-frame-hdr -V -Qy -m 
elf32ppclinux -dynamic-linker /lib/ld.so.1 -o t /usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/../../../../lib/crt1.o /usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/../../../../lib/crti.o /usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/crtbegin.o -L/usr/lib/gcc-lib/powerpc-suse-linux/3.3.3 -
L/usr/lib/gcc-lib/powerpc-suse-linux/3.3.3/../../../../powerpc-suse-
linux/lib/../lib -L/usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/../../../../powerpc-suse-linux/lib -L/usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/../../../../lib -L/usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/../../.. -L/lib/../lib -L/usr/lib/../lib t.o -lstdc++ -lm -lgcc_s -
lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/crtsavres.o /usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/crtend.o /usr/lib/gcc-lib/powerpc-suse-
linux/3.3.3/../../../../lib/crtn.o
GNU ld version 2.15.90.0.1.1 20040303 (SuSE Linux)
  Supported emulations:
   elf32ppclinux
   elf32ppc
   elf32ppcsim
   elf64ppc
Return code: 0
+42
42
Return code: 0

Expected output
===========================================
Return code: 0
42
42
Return code: 0
Comment 1 Grigor Nikolov 2004-05-21 17:00:04 UTC
Created attachment 6355 [details]
preprocessed file
Comment 2 Andrew Pinski 2004-05-21 17:16:23 UTC
Confirmed.
Comment 3 CVS Commits 2004-05-22 09:03:16 UTC
Subject: Bug 15565

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2004-05-22 09:02:56

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc 
	libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t: 1.cc 2.cc 
	                                                      3.cc 4.cc 
	                                                      5.cc 6.cc 
	                                                      8.cc 
Added files:
	libstdc++-v3/testsuite/22_locale/num_put/put/char: 15565.cc 
	libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t: 15565.cc 

Log message:
	2004-05-22  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/15565
	* include/bits/locale_facets.tcc (__int_to_char(unsigned long),
	__int_to_char(unsigned long long)): Showpos is not relevant
	for unsigned types.
	* testsuite/22_locale/num_put/put/char/15565.cc: New.
	* testsuite/22_locale/num_put/put/wchar_t/15565.cc: New.
	
	* testsuite/22_locale/num_put/put/wchar_t/1.cc: Use L for the fill
	char.
	* testsuite/22_locale/num_put/put/wchar_t/2.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/3.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/4.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/5.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/6.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/8.cc: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2489&r2=1.2490
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&r1=1.191&r2=1.192
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc.diff?cvsroot=gcc&r1=1.6&r2=1.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc.diff?cvsroot=gcc&r1=1.5&r2=1.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc.diff?cvsroot=gcc&r1=1.3&r2=1.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc.diff?cvsroot=gcc&r1=1.4&r2=1.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 4 CVS Commits 2004-05-27 15:37:20 UTC
Subject: Bug 15565

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	paolo@gcc.gnu.org	2004-05-27 15:37:16

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/bits: locale_facets.tcc 
	libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t: 1.cc 2.cc 
	                                                      3.cc 4.cc 
	                                                      5.cc 6.cc 
	                                                      8.cc 
Added files:
	libstdc++-v3/testsuite/22_locale/num_put/put/char: 15565.cc 
	libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t: 15565.cc 

Log message:
	2004-05-27  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/15565
	* include/bits/locale_facets.tcc (__int_to_char(unsigned long),
	__int_to_char(unsigned long long)): Showpos is not relevant
	for unsigned types.
	* testsuite/22_locale/num_put/put/char/15565.cc: New.
	* testsuite/22_locale/num_put/put/wchar_t/15565.cc: New.
	
	* testsuite/22_locale/num_put/put/wchar_t/1.cc: Use L for the fill
	char.
	* testsuite/22_locale/num_put/put/wchar_t/2.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/3.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/4.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/5.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/6.cc: Likewise.
	* testsuite/22_locale/num_put/put/wchar_t/8.cc: Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2224.2.116&r2=1.2224.2.117
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.166.2.11&r2=1.166.2.12
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/char/15565.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/15565.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.5&r2=1.5.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/2.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.4&r2=1.4.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/3.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.4&r2=1.4.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/4.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2.12.1&r2=1.2.12.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/5.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.4&r2=1.4.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/6.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2&r2=1.2.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/8.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1&r2=1.1.12.1

Comment 5 Paolo Carlini 2004-05-27 15:39:35 UTC
Fixed for 3.4.1.
Comment 6 CVS Commits 2004-07-30 17:46:09 UTC
Subject: Bug 15565

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	paolo@gcc.gnu.org	2004-07-30 17:46:01

Modified files:
	libstdc++-v3   : ChangeLog.hammer 
	libstdc++-v3/include/bits: locale_facets.tcc 
	libstdc++-v3/testsuite/27_io: filebuf_members.cc 

Log message:
	2004-07-30  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/15565
	* include/bits/locale_facets.tcc (__int_to_char(unsigned long),
	__int_to_char(unsigned long long)): Showpos is not relevant
	for unsigned types.
	
	2004-07-30  Paolo Carlini  <pcarlini@suse.de>
	
	Backport from mainline/3.4:
	2003-04-22  Loren J. Rittle  <ljrittle@acm.org>
	
	* testsuite/27_io/filebuf_members.cc (test_06): Adjust timings
	to avoid spurious failures.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.26&r2=1.1.2.27
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/locale_facets.tcc.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.82.2.20&r2=1.82.2.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/filebuf_members.cc.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.16.18.5&r2=1.16.18.6