This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/16251] New: bogus default constructor for std::basic_iostream


% gcc -v
Reading specs from
/tmp_mnt/software/software/gcc/3.4.0/HP-UX-B.11/lib/gcc/hppa2.0w-hp-hpux11.00/3.4.0/specs
Configured with: ../configure --prefix=/software/gcc/3.4.0
--exec-prefix=/software/gcc/3.4.0/HP-UX-B.11 --with-local-prefix=/work
--enable-languages=c,c++ --enable-shared --with-gnu-as --with-as=/work/bin/as
Thread model: single
gcc version 3.4.0

c% cat t.cxx
#include <iostream>
class mystream : public std::iostream {
public:
  mystream () {};
};

int main() {
  mystream x;
  x.rdbuf(std::cout.rdbuf());
  x << "foobar" << std::endl;
}
% g++ -o t t.cxx
% ./t
./t
terminate called after throwing an instance of 'std::bad_cast'
  what():  St8bad_cast
foobarIOT trap (core dumped)

Analysis: in 3.4.0 a default constructor for basic_istream() was added
(include/.../istream, #562ff)
    protected:
      explicit 
      basic_istream(): _M_gcount(streamsize(0)) { }

which leaves the iostream in an ill state.  The other CTOR calls
this->init(__sb) which initializes the submembers correctly (ties, exceptions etc).

If I use 
     mystream () : std::iostream(NULL) {};
in the mystream class definition, the error does not occur.


3.3.2 refuses to compile the above, since no basic_iostream(void) CTOR is found.

IMHO the default CTORs should not leave the object in an ill-defined state.
(call init(NULL)).

The same problem is also present in basic_istream and basic_ostream (mayne
others as well).

Best 
R'

-- 
           Summary: bogus default constructor for std::basic_iostream
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ralfixx at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: hppa2.0w-hp-hpux11.00
  GCC host triplet: hppa2.0w-hp-hpux11.00
GCC target triplet: hppa2.0w-hp-hpux11.00


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]