Add custom ODR-safe assert.

This is in response to an issue encountered when compiling with C++20 modules.

It turns out that the use of __FILE__ or assert in headers can lead to ODR violations, since the filename is expanded to a string token which differs depending on the relative path used to include a given header. Normally, the compiler would ignore this, and select one of the implementations when linking. However, with C++20 modules, these ODR violations become breaking compile errors.

The work-around is to write a custom assert that uses __builtin_FILE() when available.

The implementation here tries to use __builtin_FILE() and __assert_fail() when available. This allows the safe use of asserts for GCC, MSVC, Clang, and NVCC (after CUDA 11).

Merge request reports

Loading