thrust icon indicating copy to clipboard operation
thrust copied to clipboard

Replace runtime_static_assert tests with compile tests.

Open alliepiper opened this issue 3 years ago • 0 comments

Some of the Thrust unit tests check that static assertions fire under particular situations. For example, generate_const_iterators tests that thrust::generate and thrust::fill trigger static assertions when called with const iterators.

This is implemented by redefining the THRUST_STATIC_ASSERT macros to instead call a function that sets some state, which is verified in the unit test. This has the unfortunate side effect of making the THRUST_STATIC_ASSERT macro unusable in certain situations:

0 |   template <typename T>
1 |   struct Foo
2 |   {
3 |     THRUST_STATIC_ASSERT(sizeof(T) <= 4);
4 |   };

Adding such a usage of THRUST_STATIC_ASSERT to any header pulled in by these tests results in some inscrutable build failures. nvcc fails with:

foo.h(3): error: expected a type specifier
foo.h(3): error: expected a type specifier
foo.h(3): error: expected a type specifier
foo.h(3): error: explicit type is missing ("int" assumed)
foo.h(3): error: qualifier must be base class of "thrust::detail::Foo<T>"

These have the nice advantage of being able to run multiple assertion checks in a single test, but they limit our ability to develop the library. Additionally, the techniques used to implement them aren't compatible with nvc++ and these tests are disabled for that compiler.

We should replace these with compilation tests using CMake. This would also let us test for other expected build passes/failures besides static asserts.

In the meantime, the syntax issue can be worked-around using a raw C++11 static_assert.

alliepiper avatar Apr 27 '22 02:04 alliepiper