template <typename T>
struct Slice {
T* data = nullptr;
size_t size = nullptr;
T& operator[](size_t index) {
if (index >= size) crash_the_program();
return data[index];
}
};
If you're considering this extension, just use C++ and 5 lines of standard, portable, no-weird-annotations code instead.The extension is for hardening legacy C code without breaking ABI.
Even better, starting with C++26, and considered to be done with DR for previous versions, hardned runtimes now have a portable way to be configured across compilers, instead of each having their own approach.
However, you still need something like -fbounds-safety in C++, due to the copy-paste compatibility with C, and too many people writing Orthodox C++, C with Classes, Better C, kind of code, that we cannot get rid of.
You should tell the LLVM folks, I guess they didn't know about this.
size_t size = nullptr;
watand if you write directly in assembly you don't even need a C++ compiler
Or just do it in C.
https://godbolt.org/z/TvxseshGc