kokkos / mdspan

Reference implementation of mdspan targeting C++23
Other
398 stars 65 forks source link

Fix LWG Issue 4060 (fix submdspan to prevent invalid pointer creation) #323

Closed mhoemmen closed 3 months ago

mhoemmen commented 4 months ago

Link to issue: https://cplusplus.github.io/LWG/issue4060

  1. Fix submdspan to prevent invalid pointer creation
  2. Implement bounds checking for the various layouts, so we can actually detect the issue

I aimed for C++14 backwards compatibility. Item (2) above is not strictly necessary to fix the issue, but it does help with finding the issue in the first place.

Bounds checking is only enabled in a debug build (if NDEBUG is not defined). It involves some fold expressions over assert expressions. I'm not attached to the use of assert for reporting errors.