SunStudio 11 C++ std::stringstream stream pointer problem

Example program to demonstrate that the stream pointer for

std::stringstream streams is not always set correctly after writing

a char array to the stream.

Problem is present in SunStudio 11:

Sun C++ 5.8 Patch 121017-04 2006/08/02

No special compile options, standard C++ library

[code]

#include <string>

#include <sstream>

#include <iostream>

int main( int argc, char *argv[] )

{

std::stringstream os;

char cbuf[1000];

for ( int i=0;i<sizeof(cbuf);i++) cbuf[i]='a';

// Write contents of char array to the stringstream. The stream

// pointer is not incremented. The flush() call doesn't help.

os.write(cbuf, sizeof(cbuf));

os.flush();

std::cout ><< "Position after char* write is wrong: " \

<< os.tellp() << std::endl;

// After appending to the stringstream the stream pointer is

// now correct.

os << "A";

std::cout << "Position after std::string append is ok: " \

<< os.tellp() << std::endl;

return 0;

}

[/code]

[1158 byte] By [Colin.McDonald] at [2007-11-26 10:26:35]
# 1
I believe you have found a bug in the default libCstd implementation of iostreams.Please file a bug report at bugs. sun.com.
clamage45 at 2007-7-7 2:30:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
A bug has been filed at bugs.sun.com, bug number 6476301.
clamage45 at 2007-7-7 2:30:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
I can't find the bug in the database. What is the expected behavior? I get 1000 and 1001 with libCstd, the latest stdcxx, STLport, and g++, and that looks good to me.
sebor@roguewavecom at 2007-7-7 2:30:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
With the latest SunStudio 11 patches:CC: Sun C++ 5.8 Patch 121017-04 2006/08/02on Solaris 10 06/06:SunOS 5.10 Generic_118833-17 sun4u sparc SUNW,Sun-Blade-1000compiling and linking with libCstd:CC-o test_sstream test_sstream.ccoutputs -1, 1001
ColinMcDonald at 2007-7-7 2:30:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5

Hmm. I get 1000 and 1001 with 5.8:

$ CC -V t.cpp && ./a.out

CC: Sun C++ 5.8 Patch 121017-01 2005/12/11

/amd/packages/mdx/solaris/SUNWspro/C++5.8j1/prod/bin/c++filt: Sun C++ 5.8 2005/10/13

ccfe: Sun C++ 5.8 Patch 121017-01 2005/12/11

ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.480

Position after char* write is wrong: 1000

Position after std::string append is ok: 1001

sebor@roguewavecom at 2007-7-7 2:30:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

So perhaps it is a regression in one of the CC patches 121017-02

to -04?

Or a difference in the libCstd.so? On my Solaris 10 6/06 system:

$ ls -l /usr/lib/libC*

-rwxr-xr-x1 rootbin100764 Jan 23 2005 /usr/lib/libC.so.3*

-rwxr-xr-x1 rootbin391268 Mar 10 2006 /usr/lib/libC.so.5*

-rwxr-xr-x1 rootbin63628 Mar 10 2006 /usr/lib/libCrun.so.1*

-rwxr-xr-x1 rootbin1899836 Mar 10 2006 /usr/lib/libCstd.so.1*

ColinMcDonald at 2007-7-7 2:30:20 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7

I just compiled this code on Solaris 10, Solaris 10 6/06 s10s_u2wos_09a SPARC

./test_sstream

Position after char* write is wrong: -1

Position after std::string append is ok: 1001

CC -V

CC: Sun C++ 5.8 Patch 121017-04 2006/08/02

Same result on pretty well patched Solaris 9 and 8. With the same compiler.

AndersG at 2007-7-7 2:30:20 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8
Looks like it's a regression between the two patches then.
sebor@roguewavecom at 2007-7-7 2:30:20 > top of Java-index,Development Tools,Solaris and Linux Development Tools...