C++ wrapper iostream input bug

Helmut Jarausch jarausch at igpm.rwth-aachen.de
Mon Apr 19 13:01:03 CEST 2010

On 19 Apr, Marc Glisse wrote:
> On Mon, 22 Mar 2010, Helmut Jarausch wrote:
>> The 'operator>>' in the C++ wrapper library fails if the input
>> is not terminated by white space - see the example.
>> This doesn't fail for the input operator in general, just for
>> gmpxx.
> Hello,
> let me check whether I understand how it works.

Unfortunately it's even worse.
> 1) when the exception mask is clear, gmp works fine (actually there is a 
> bug that makes it clear the eof flag too eagerly, but let's ignore that 
> for now)

On a "standard" Linux system it works since it only occurs at the very
last input. So, if one doesn't check the flags, it works.
But I noticed this bug when running an application on MinGW.
There, this input is just ignored which made the application fail.
(And was quite hard to locate).

> 2) it may happen that the fail flag is temporarily set and then cleared 
> during the execution of the function.
> ==> Things would work as you expect if for such functions gmp saved the 
> exception mask, cleared it, executed the current code and finally restored 
> the mask.

But, turning exceptions off is something like a compatibility option for
"old" code. Modern code will (should?) turn exceptions on.
Therefore it's a bug even on a "standard" Linux system.

Thanks for looking into it.
I think it should be easy to correct. If the EOF or EOS condition occurs
during initial white space skipping or before reading the very first
digit, it's a true EOF error condition. If it occurs after at least one
digit has been read it's absolutely normal and the EOF condition should
only be reported after one tries to read again from that istream.


Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany

More information about the gmp-bugs mailing list