Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn .ptr deprecation into an error #7688

Merged
merged 1 commit into from
Jan 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions changelog/ptr-safe-end-of-deprecation.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
`.ptr` on arrays can no longer be used in `@safe` code

The deprecation period for using `.ptr` on arrays in `@safe` ended.
The following now triggers an error instead of a deprecation:

---
@safe ubyte* oops(ubyte[] arr) {
return arr.ptr;
}
---

Use `&arr[0]` instead:

---
@safe ubyte oops(ubyte[] arr) {
return &arr[0];
}
---

Note that this only applies to SafeD - in `@system` code `.ptr` may still be used:

---
@system ubyte* oops(ubyte[] arr) {
return arr.ptr;
}
---
10 changes: 4 additions & 6 deletions src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -4688,9 +4688,8 @@ extern (C++) final class TypeSArray : TypeArray
}
else if (!(flag & DotExpFlag.noDeref) && sc.func && !sc.intypeof && sc.func.setUnsafe())
{
// MAINTENANCE: turn into error in 2.073
e.deprecation("`%s.ptr` cannot be used in `@safe` code, use `&%s[0]` instead", e.toChars(), e.toChars());
// return new ErrorExp();
e.error("`%s.ptr` cannot be used in `@safe` code, use `&%s[0]` instead", e.toChars(), e.toChars());
return new ErrorExp();
}
e = e.castTo(sc, e.type.nextOf().pointerTo());
}
Expand Down Expand Up @@ -4950,9 +4949,8 @@ extern (C++) final class TypeDArray : TypeArray
{
if (!(flag & DotExpFlag.noDeref) && sc.func && !sc.intypeof && sc.func.setUnsafe())
{
// MAINTENANCE: turn into error in 2.073
e.deprecation("`%s.ptr` cannot be used in `@safe` code, use `&%s[0]` instead", e.toChars(), e.toChars());
// return new ErrorExp();
e.error("`%s.ptr` cannot be used in `@safe` code, use `&%s[0]` instead", e.toChars(), e.toChars());
return new ErrorExp();
}
e = e.castTo(sc, next.pointerTo());
return e;
Expand Down
6 changes: 3 additions & 3 deletions test/fail_compilation/test11176.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
REQUIRED_ARGS: -de
TEST_OUTPUT:
---
fail_compilation/test11176.d(12): Deprecation: b.ptr cannot be used in @safe code, use &b[0] instead
fail_compilation/test11176.d(16): Deprecation: b.ptr cannot be used in @safe code, use &b[0] instead
fail_compilation/test11176.d(12): Error: `b.ptr` cannot be used in `@safe` code, use `&b[0]` instead
fail_compilation/test11176.d(16): Error: `b.ptr` cannot be used in `@safe` code, use `&b[0]` instead
---
*/

Expand Down