public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* question: is it a compiler bug or else? PART 2
@ 2013-11-19 13:05 Graziano Servizi
  0 siblings, 0 replies; only message in thread
From: Graziano Servizi @ 2013-11-19 13:05 UTC (permalink / raw)
  To: gcc-help

Hi,

I am GS again; in addition to my question of yesterday I made some 
further attempts: here follows an updated version of my sample code:

// code begins
# include <iostream>
# include <fstream>
# include <sstream>
# include <exception>
# include <system_error>
using namespace std;

int main( )
  {
   istringstream is("abcdefghijklmnopqrstuvwxyz");
   //ifstream is("file"); // with the same content
    cout << "begins: " << is . tellg( ) << '\n';
   char c = is.get( );
   cout << "after get " << is . tellg( ) << " with " << is . gcount( ) 
<< " and c is [" << c << "]\n";
   is.seekg(2, ios::cur); // move ahead two bytes
   cout << "after seekg " << is . tellg( ) << " with " << is . gcount( ) 
<< '\n';
   cout << "STATE A " << is.rdstate() << '\n';
   is . putback(c); // shouldn't set badbit ??
   try
    {
     is . exceptions(is . badbit);
     // moreover neither this exception is thrown
     }
   catch(ios_base :: failure & e)
    {cout << "caught!\n";
     cout << e.what() << '\n' /*<<  e.code() << '\n'*/;
     // and in addition ios_base::failure objects seem NOT to inherit
     // the function code()  from std :: system_error
     // (that's why it is commented out): what happens?
      }
   cout << "STATE B " << is.rdstate() << '\n';
   // it turns out that badbit is not set (same output [0] in STATE A as 
in STATE B)
   // however...the stream appears to be at eof...and accordingly c is 
unaffected by get():
   cout << "after putback " << is . tellg( ) << " with " << is . gcount( 
) << " and next byte will be [";
   cout << (c = is.get( )) << "]\n";
}
// code ends

with embedded comments where I tried to explain what kind of problems I met.

Meanwhile I saw that it is known the lacking of inheritance of "failure"
from "system_error": is it planned to fix this?

Please note that NO PROBLEM OCCURS when the "istringstream" class is 
used instead of "ifstream" (I mean: the badbit is set and the exception 
is thrown and caught). I already knew this, but nevertheless why should 
the "ifstream" class clearly put the stream at eof WITHOUT MAKING THE 
PROGRAM AWARE of that in any way?

Thanks again. Hoping for an answer...or a fix of my code.

                                 G. Servizi

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-11-19 11:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 13:05 question: is it a compiler bug or else? PART 2 Graziano Servizi

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).