toolchain icon indicating copy to clipboard operation
toolchain copied to clipboard

[dejagnu: libstdc++] C++11: STOF doesn't throw out_of_range exception

Open fbedard opened this issue 6 years ago • 0 comments

The libstdc++ implementation of stoff doesn't throw out_of_range exception. For all other exceptions it appears to behave correctly.

Errors: FAIL: 21_strings/basic_string/numeric_conversions/char/stof.cc execution test FAIL: 21_strings/basic_string/numeric_conversions/wchar_t/stof.cc execution test

Simplified test case:

#include <iostream>
#include <string>
#include <limits>
#include <stdexcept>
# include <cassert>
# define VERIFY(fn) assert(fn)

void
test01()
{
  bool test __attribute__((unused)) = false;
  using namespace std;

  float f1 = 0.0f;
  size_t idx1 = 0;

  test = false;
  f1 = -1.0f;
  try
    {
      f1 = stof("34028234663852885981170418348451692544000.000000");
    }
  catch(std::out_of_range)
    {
      test = true;
    }
  catch(...)
    {
    }
  cout << "Test : " << test << endl;
  cout << "F1   : " << f1 << endl;
  VERIFY( test );
  VERIFY( f1 == -1.0f );
}

int main()
{
  test01();
  return 0;
}

Notes: the stof calls div operations, however, the div ops are not trapping. Thus we may need to add #define __glibcxx_integral_traps false in CPU specific cpu_define.h file (i.e., libstdc++-v3/config/cpu/arc/cpu_defines.h ).

fbedard avatar Jun 25 '18 17:06 fbedard