This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/15565] New: SLES9: leading + sign for unsigned int with showpos
- From: "grigor at ca dot ibm dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 21 May 2004 16:57:11 -0000
- Subject: [Bug libstdc++/15565] New: SLES9: leading + sign for unsigned int with showpos
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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
--
Summary: SLES9: leading + sign for unsigned int with showpos
Product: gcc
Version: 3.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: grigor at ca dot ibm dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15565