When I try and "copy" a basic_ifstream<uint8_t> into a vector<uint8_t> I recieve a bad cast exception. If the uint8_t is replaced with "unsigned char" explicitly the problem persists, but if it is replaced with "char" the problem goes away.
This has been confirmed not only on my system (GCC 4.1.1), but an Ubuntu system running GCC 4.0.3 and another running GCC 4.1.2. The code compiles and works fine under Microsoft Visual Studio .NET 2005. The g++ problem has not been tested on a Windows system. ------ #include <vector> #include <iterator> #include <fstream> #include <iostream> #include <sstream> #ifndef WIN32 #include "stdint.h" #else typedef unsigned char uint8_t; #endif using namespace std; int main(int argc, char **argv) { if (argc != 2) { cout << "Usage: " << argv[0] << " <log filename>" << endl; return 1; } // Open the input file basic_ifstream<uint8_t> inputFile(argv[1], ios::binary); if (inputFile.fail()) { cout << "Failed to open the input file" << endl; return 2; } // Read the file into a vector vector<uint8_t> inputData; istreambuf_iterator<uint8_t> inputDataStartIterator(inputFile), inputDataEndIterator; copy(inputDataStartIterator, inputDataEndIterator, back_inserter(inputData)); } ---- Command that triggers the bug: g++ test.cpp -- Summary: bad_cast when using copy on istreambuf_iterator<unsigned char> Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: batterseapower at hotmail dot com GCC build triplet: /var/tmp/portage/sys-devel/gcc-4.1.1-r3/work/gcc- 4.1.1/configure GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31901