Asserting a null byte follows a std::span in memory
#include
#include
int main(int argc, char **argv)
{
// 1) According to the standard, this must pass:
assert(argv[argc] == nullptr);
std::span spn { argv, argv + argc };
// 2) Undefined behavior
assert(spn[argc] == nullptr);
// 3) Is this allowed ?
assert(spn.data()[argc] == nullptr);
}
The question is about the third assert
Since I do not index the span itself, but rather take the address and basically treat it as an array, I believe this is correct (and it passes).
According to Chatgpt, this is UB.
So the question is:
Is the 3rd assert statement well-defined behavior and will it pass ?