While libstdc++ does not, libc++ does follow the standard which states that passing ios_base::failbit
to basic_istream::exceptions
has no effect on formatted input. For example this code:
istringstream is{"ASD"};
double foo;
is.exceptions(istream::failbit);
try {
is >> foo;
cout << foo << endl;
} catch(ios_base::failure& fail) {
cout << "ouch\n";
}
Would result in:
My reading of LWG2349 is that it would cause basic_istream
to not throw on any formatted input.
For example LWG2349 proposes a change to the standard's 27.7.2.3 [istream]/1 which was cited with reference to the invalidation of a bug that would have made libc++ behave like libstdc++. The change is in bold and strike through below:
If an exception , other than the ones thrown from
clear()
, if any, is thrown during input thenios::badbit
is turned on in*this
’s error state.(Exceptions thrown fromIfbasic_ios<>::clear()
are not caught or rethrown.)(exceptions()&badbit) != 0
then the exception is rethrown.
I understand that basic_istream::clear
is what throws in reaction to bad formatted input so am I misreading LWG2349 or is it in fact going to stop basic_istream
from throwing any errors?
clear()
will continue to throw in that case, it just will not setbadbit
." And that throw would still not be rethrown, if theexceptions() & ios_base::badbit == 0
, right? So this won't do anything to align the question's example behaviors of libc++ and libstdc++? – Kinnon