[libc++] Writing to a read-only std::filebuf

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[libc++] Writing to a read-only std::filebuf

Tom Stellard via cfe-dev
I tried the following code on Ubuntu16.10 with the package
libc++-dev:amd64 (3.7.0-1).
There is a different behavior between libstdc++ and libc++:

 >clang++-3.9 -stdlib=libstdc++ test.cpp && ./a.out
97 98 97 98 -1 -1

 >clang++-3.9 -stdlib=libc++ test.cpp && ./a.out
97 98 97 98 -1 100

Is this a bug?
Thanks,
Fulvio Benini



#include <fstream>
#include <iostream>

int main() {
{ //Create a temporary file.
   std::filebuf file;
   file.open("tmp_file", std::ios_base::in | std::ios_base::out
                         std::ios_base::trunc | std::ios_base::binary);
   std::cout << file.sputc('a') << ' ';
   std::cout << file.sputc('b') << ' ';
}
{ //Re-open the file read-only.
   std::filebuf file;
   file.open("tmp_file", std::ios_base::in | std::ios_base::binary);
   std::cout << file.sbumpc() << ' ';
   std::cout << file.sbumpc() << ' ';
   file.pubseekpos(0);
   std::cout << file.sputc('c') << ' ';
   //The next sputc() should return EOF?
   std::cout << file.sputc('d') << ' ';
}
   std::cout << std::endl;
}
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...