[Issue 20964] poor CTFE support for backward pointer iteration
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Sep 22 10:06:38 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=20964
Stefan Koch <uplink.coder at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |uplink.coder at gmail.com
--- Comment #6 from Stefan Koch <uplink.coder at gmail.com> ---
To make this code example clearer:
this compiles without complaints in non- at safe code and works.
void main()
{
uint[3] arr = [1,2,3];
assert(foo(arr) == arr[0]);
}
uint foo(uint[3] m)
{
auto p = &m[0]; // pointing the first element
p += 8; // pointing to an invalid address &m[9]
p -= 11; // pointer to an invalid address &[m-2]
p++; // after this statement pointing the valid address &m[-1] again
return *++p; // *p should yield m[0];
}
Because at ctfe we can actually check that the final position of the pointer
the point of using it to access memory is in the range of the original memory
block;
I have no issues with allowing this.
--
More information about the Digitalmars-d-bugs
mailing list