The following test program returns different results depending on whether I'm using libc++ or libstdc++.
#include <sstream>
#include <iostream>
int main()
{
int a = 0;
void* optr = &a;
void* iptr;
std::stringstream ss;
ss << optr;
std::cout << ss.str() << '\n';
ss >> iptr;
std::cout << iptr << '\n';
return 0;
}
I'm using the following version of clang from Xcode 5 on OSX 10.9.2
$ xcrun clang++ --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Here's the output of the test when built with libstdc++ and libc++
$ xcrun clang++ test.cpp <-- libstdc++ version
$ ./a.out
0x7fff5ec723e8
0x7fff5ec723e8
$ xcrun clang++ test.cpp -stdlib=libc++ <-- libc++ version
$ ./a.out
0x7fff5205125c
0x7fff5
Is this a bug in the libc++ implementation of stringstream? Is this usage of void* with stringstream valid C++?
Thanks!
Yes! it's a bug in libc++, probably in the implementation of
__sscanf_l
(somescanf
lookalike that should take locales into consideration). The libstdc++ implemementation is much simpler.versus
This has been fixed in libc++ as of revision 209305.