mardi 24 avril 2018

Are stringstream read failures non-deterministic?

I have some code that behaves differently on different compiler's:

std::string strVal = "11";
std::stringstream stream( strVal );  
auto value = false;

if( !( stream >> std::noboolalpha >> value ) )
{
    // report error - this path is taken on both compilers
}

// "value" is "false" here on in VS 2017, but "true" on GCC 460

Is the difference in behavior expected, or is it a bug in GCC?

According to cppprefence:

If extraction fails (e.g. if a letter was entered where a digit is expected), value is left unmodified and failbit is set.

However, value is being modified to true on GCC 460.

Aucun commentaire:

Enregistrer un commentaire