D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20988 - Missing error for negated array.ptr
Summary: Missing error for negated array.ptr
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: safe
Depends on:
Blocks:
 
Reported: 2020-06-28 17:16 UTC by moonlightsentinel
Modified: 2020-07-13 17:38 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description moonlightsentinel 2020-06-28 17:16:00 UTC
The following code compiles without raising an error regarding `arr.ptr`.

void main() @safe
{
    uint[] arr = [1, 2, 3];
    bool b = !arr.ptr;
}
Comment 1 moonlightsentinel 2020-06-28 19:53:01 UTC
Checking array.ptr is @safe as long as it isn't dereferenced
Comment 2 hsteoh 2020-07-13 17:38:33 UTC
There doesn't seem to be a real problem here?  `b` would just be set to true if arr.ptr is null, and false otherwise.

Accessing the value of a pointer is perfectly fine in @safe. Even deferencing a pointer is fine, since any pointer value constructed in a @safe manner would not point to something invalid.  What's not allowed in @safe is *pointer arithmetic*.