This is an archive of the discontinued LLVM Phabricator instance.

Protect bitset tests under libcpp-no-exceptions
ClosedPublic

Authored by rogfer01 on Oct 31 2016, 4:06 AM.

Details

Summary

Bitset tests feature a sequence of tests of increasing bitset sizes,
but these tests rely on exceptions when the bitset size is less than
50 elements. So under libcpp-no-exceptions do not run the
smaller-than-50 tests.

Diff Detail

Repository
rL LLVM

Event Timeline

rogfer01 updated this revision to Diff 76375.Oct 31 2016, 4:06 AM
rogfer01 retitled this revision from to Protect bitset tests under libcpp-no-exceptions.
rogfer01 updated this object.
rogfer01 added reviewers: mclow.lists, EricWF, rmaprath.
EricWF edited edge metadata.Nov 4 2016, 6:16 PM

Instead of just #ifdef-ing out the tests that throw I would rather see something like this:

template <std::size_t N>
void test_test(bool test_throws)
{
    const std::bitset<N> v1 = make_bitset<N>();
#ifdef TEST_HAS_NO_EXCEPTIONS
  if (test_throws) return;
#else
    try
    {
#endif
        bool b = v1.test(50);
        if (50 >= v1.size())
            assert(false);
        assert(b == v1[50]);
       assert(!test_throws);
#ifndef TEST_HAS_NO_EXCEPTIONS
    }
    catch (std::out_of_range&)
    {
       assert(test_throws);
    }
#endif
}

int main()
{
  // Throwing cases
   test_test<33>(true);
  // Non-throwing cases
    test_test<63>(false);
}
rogfer01 updated this revision to Diff 77360.Nov 9 2016, 9:09 AM
rogfer01 edited edge metadata.

Do not "ifdef" out tests that throw, use a runtime flag for them instead.

EricWF accepted this revision.Nov 9 2016, 10:16 AM
EricWF edited edge metadata.
This revision is now accepted and ready to land.Nov 9 2016, 10:16 AM
This revision was automatically updated to reflect the committed changes.