D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20989 - Checking array.ptr causes safety error with -checkaction=context
Summary: Checking array.ptr causes safety error with -checkaction=context
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-06-28 19:57 UTC by moonlightsentinel
Modified: 2020-07-09 21:25 UTC (History)
0 users

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 19:57:42 UTC
The following code fails to compile with -checkaction=context:

========================================
void main() @safe
{
    uint[] arr = [1, 2, 3];
    assert(!arr.ptr);
    assert(arr.ptr is arr.ptr);
}
========================================

dmd --checkaction=context safety.d
safety.d(6): Error: arr.ptr cannot be used in @safe code, use &arr[0] instead
safety.d(7): Error: arr.ptr cannot be used in @safe code, use &arr[0] instead
safety.d(7): Error: arr.ptr cannot be used in @safe code, use &arr[0] instead

========================================
Comment 1 Dlang Bot 2020-06-28 20:12:27 UTC
@MoonlightSentinel created dlang/dmd pull request #11337 "Fix Issue 20989 - Checking array.ptr causes safety error ..." fixing this issue:

- Fix Issue 20989 - Checking array.ptr causes safety error ...
  
  ... with -checkaction=context.
  
  Explicity flag `DotIdExpressions` as `noderef` because `_d_assert_fail` will
  not dereference the pointer and thus make the call `@safe`.

https://github.com/dlang/dmd/pull/11337
Comment 2 Dlang Bot 2020-07-04 12:00:15 UTC
dlang/dmd pull request #11337 "Fix Issue 20989 - Checking array.ptr causes safety error ..." was merged into stable:

- 8591c1da46903cc97c13efb1dbe79a4e7f1872ab by MoonlightSentinel:
  Fix Issue 20989 - Checking array.ptr causes safety error ...
  
  ... with -checkaction=context.
  
  Explicity flag `DotIdExpressions` as `noderef` because `_d_assert_fail` will
  not dereference the pointer and thus make the call `@safe`.

https://github.com/dlang/dmd/pull/11337
Comment 3 Dlang Bot 2020-07-09 21:25:59 UTC
dlang/dmd pull request #11400 "merge stable" was merged into master:

- 95be29f324c6eb655ff93807102120d7d5c80ee5 by MoonlightSentinel:
  Fix Issue 20989 - Checking array.ptr causes safety error ...
  
  ... with -checkaction=context.
  
  Explicity flag `DotIdExpressions` as `noderef` because `_d_assert_fail` will
  not dereference the pointer and thus make the call `@safe`.

https://github.com/dlang/dmd/pull/11400