Bug#271300: g++-3.4: ostreams misbehaving when used as temporaries
Package: g++-3.4
Version: 3.4.2-2
Severity: normal
This code:
----------------------------------------
#include <sstream>
#include <iostream>
int main() {
std::cout << static_cast<std::ostringstream &>(std::ostringstream() << 'a' << "a").str() << std::endl;
std::cout << static_cast<std::ostringstream &>(std::ostringstream() << "a" << "a").str() << std::endl;
}
----------------------------------------
.... prints under g++-3.3 and g++-3.4:
97a
0x804b6e0a
I expected:
aa
aa
(I get the expected behaviour with g++-2.95.)
Similar behaviour is exhibited if an ofstream is used in place of an
ostringstream:
----------------------------------------
#include <fstream>
#include <iostream>
int main() {
std::ofstream("one") << 'a' << "a" << std::endl;
std::ofstream("two") << "a" << "a" << std::endl;
}
----------------------------------------
g@crash:~/tmp$ cat one two
97a
0x8048b98a
It seems that if the first thing given to the ostream is a:
-- char literal ('a'), the compiler treats it as an int (97)
-- string literal ("a"), the compiler treats it as a void *
(0x804b6e0a).
-- System Information:
Debian Release: 3.1
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.0
Locale: LANG=C, LC_CTYPE=C
Versions of packages g++-3.4 depends on:
ii gcc-3.4 3.4.2-2 The GNU C compiler
ii gcc-3.4-base 3.4.2-2 The GNU Compiler Collection (base
ii libc6 2.3.2.ds1-16 GNU C Library: Shared libraries an
ii libstdc++6-dev 3.4.2-2 The GNU Standard C++ Library v3 (d
-- no debconf information
Reply to: