public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31901]  New: bad_cast when using copy on istreambuf_iterator<unsigned char>
@ 2007-05-11 18:03 batterseapower at hotmail dot com
  2007-05-11 18:05 ` [Bug c++/31901] " batterseapower at hotmail dot com
  2007-05-11 18:10 ` pcarlini at suse dot de
  0 siblings, 2 replies; 3+ messages in thread
From: batterseapower at hotmail dot com @ 2007-05-11 18:03 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/31901] bad_cast when using copy on istreambuf_iterator<unsigned char>
  2007-05-11 18:03 [Bug c++/31901] New: bad_cast when using copy on istreambuf_iterator<unsigned char> batterseapower at hotmail dot com
@ 2007-05-11 18:05 ` batterseapower at hotmail dot com
  2007-05-11 18:10 ` pcarlini at suse dot de
  1 sibling, 0 replies; 3+ messages in thread
From: batterseapower at hotmail dot com @ 2007-05-11 18:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from batterseapower at hotmail dot com  2007-05-11 19:04 -------
Created an attachment (id=13541)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13541&action=view)
Preprocessed C++ source code for my test application


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31901


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/31901] bad_cast when using copy on istreambuf_iterator<unsigned char>
  2007-05-11 18:03 [Bug c++/31901] New: bad_cast when using copy on istreambuf_iterator<unsigned char> batterseapower at hotmail dot com
  2007-05-11 18:05 ` [Bug c++/31901] " batterseapower at hotmail dot com
@ 2007-05-11 18:10 ` pcarlini at suse dot de
  1 sibling, 0 replies; 3+ messages in thread
From: pcarlini at suse dot de @ 2007-05-11 18:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pcarlini at suse dot de  2007-05-11 19:09 -------
This is known and we decided time ago not to do anything about it (you can find
something either in Bugzilla or in the libstdc++ mailing list): a portable use
of fstream with anything != char and wchar_t requires in general writing a
custom codecvt.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31901


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-11 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-11 18:03 [Bug c++/31901] New: bad_cast when using copy on istreambuf_iterator<unsigned char> batterseapower at hotmail dot com
2007-05-11 18:05 ` [Bug c++/31901] " batterseapower at hotmail dot com
2007-05-11 18:10 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).