Unexpected exception in std :: ifstream

When experimenting with I / O, I get an exception where the exception should not be thrown:

#include <iostream>
#include <fstream>

int main()
{
    std::ifstream f("/tmp");
    std::cout << "Exception Flags: " << f.exceptions() << std::endl;
    if(f >> std::ws) std::cout << "This will not succeed" << std::endl;
    else std::cout << "Ok - it fails" << std::endl;
    return 0;
}

But the way out:

Exception Flags: 0
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file
Aborted

g ++ (Ubuntu / Linaro 4.7.2-2ubuntu1) 4.7.2

Edit

The test is supposed to complete without exception:

From 27.5.5.4 flag functions basic_ios

void clear (iostate state = goodbit);

4 Postcondition: If rdbuf ()! = 0, then the state == rdstate (); otherwise rdstate () == (state | ios_base :: badbit).

5 Effects: If ((state | (rdbuf ()? Goodbit: badbit)) & exceptions ()) == 0, returns. Otherwise, the function throws an object of failure of the basic_ios :: failure class (27.5.3.1.1), constructed using the value of the arguments determined by the implementation.

void setstate (iostate state);

6 : clear (rdstate() | state) ( basic_ios:: failure (27.5.3.1.1)).

+4
1

, clang v3.4 lib++ ; GCC 4.8 libstd++ -.

libstd++ , basic_ios::clear , - " ?" , .

53984.

+7

All Articles