From fdd94f316910841e44630bc14f3178f6eb2b172e Mon Sep 17 00:00:00 2001 From: skyline131313 <11180237+skyline131313@users.noreply.github.com> Date: Wed, 15 Jun 2022 11:20:06 -0400 Subject: [PATCH 1/2] Add Dip, Disallow Unsafe Declarations --- DIPs/DIP1045.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 DIPs/DIP1045.md diff --git a/DIPs/DIP1045.md b/DIPs/DIP1045.md new file mode 100644 index 000000000..33b35769b --- /dev/null +++ b/DIPs/DIP1045.md @@ -0,0 +1,55 @@ +# Disallow Unsafe Declarations + +| Field | Value | +|-----------------|-----------------------------------------------------------------| +| DIP: | | +| Review Count: | | +| Author: | skyline131313 | +| Implementation: | | +| Status: | Draft | + +## Abstract + +Disallow extern C and C++ function declarations from being marked `@safe` or `@trusted`. + +## Contents +* [Rationale](#rationale) +* [Prior Work](#prior-work) +* [Description](#description) +* [Breaking Changes and Deprecations](#breaking-changes-and-deprecations) +* [Reference](#reference) +* [Copyright & License](#copyright--license) +* [Reviews](#reviews) + +## Rationale + +Foreign code that is interfaced cannot be guaranteed to be safe. It should always be assumed as unsafe. Especially C declarations as the types used are not mangled into the name of the function. It would be possible to link to a C function with the incorrect parameter types. + +## Prior Work + +Rust declares all foreign interfaces as unsafe, they cannot be explicitly marked as safe as there is only an `unsafe` keyword. [Rust avoids the issue of marking `unsafe` foreign declarations as `safe` entirely by design](https://doc.rust-lang.org/nomicon/ffi.html). + +## Description + +Any C or C++ function declaration with the `@safe` or `@trusted` attributes will now become an error. + +```D +@safe extern(C) foo(); // Error: extern(C) declaration cannot be marked as `@safe`. +@trusted extern(C++) bar(); // Error: extern(C++) declaration cannot be marked as `@trusted`. +``` + +## Breaking Changes and Deprecations + +Any extern C and C++ declarations that are marked with `@trusted` or `@safe` will cause breaking changes. + +## Reference + + +## Copyright & License + +Copyright (c) 2022 by the D Language Foundation + +Licensed under [Creative Commons Zero 1.0](https://creativecommons.org/publicdomain/zero/1.0/legalcode.txt) + +## Reviews + From 45aaecf0a68815bdbf269386909dc3c92507ee0d Mon Sep 17 00:00:00 2001 From: skyline131313 <11180237+skyline131313@users.noreply.github.com> Date: Sun, 19 Jun 2022 08:26:17 -0400 Subject: [PATCH 2/2] Add name and contact info. --- DIPs/DIP1045.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIPs/DIP1045.md b/DIPs/DIP1045.md index 33b35769b..55d690fe6 100644 --- a/DIPs/DIP1045.md +++ b/DIPs/DIP1045.md @@ -4,7 +4,7 @@ |-----------------|-----------------------------------------------------------------| | DIP: | | | Review Count: | | -| Author: | skyline131313 | +| Author: | [Mark](markleaf131313@gmail.com) | | Implementation: | | | Status: | Draft |