Thread overview
[Issue 24098] Safe variable can be initialized from `@system` static constructor.
Mar 23
Dlang Bot
Mar 30
Dlang Bot
August 22
https://issues.dlang.org/show_bug.cgi?id=24098

--- Comment #1 from timon.gehr@gmx.ch ---
Actually, depending on how exactly you interpret "create unsafe values", I guess my `main` function may not violate requirement 2. However, I think this is still a problem for memory safety in D and worth addressing.

--
August 22
https://issues.dlang.org/show_bug.cgi?id=24098

--- Comment #2 from timon.gehr@gmx.ch ---
I think the program is still at odds with the language specification even if requirement 2 is not considered to be violated, because clearly it violates requirement 1 and the preconditions hold (the preconditions do not say anything about the state of global variables).

I think this is a related but somewhat independent bug in the specification, because there could also be `@trusted` code that messes up the state of a non-`@system` global.

--
March 22
https://issues.dlang.org/show_bug.cgi?id=24098

Nick Treleaven <nick@geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick@geany.org

--- Comment #3 from Nick Treleaven <nick@geany.org> ---
> depending on how exactly you interpret "create unsafe values", I guess my `main` function may not violate requirement 2

I think dereferencing doesn't create an unsafe value, the static ctor created an unsafe pointer, which in turn points to an unsafe value.

> clearly it violates requirement 1 and the preconditions hold (the preconditions do not say anything about the state of global variables).

Yes, I think the preconditions need to mention safe context:

> When it is only called with safe values and safe aliasing

--
March 23
https://issues.dlang.org/show_bug.cgi?id=24098

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@ntrel created dlang/dlang.org pull request #3789 "[spec] Fix Safe interface definition" mentioning this issue:

- [spec] Fix Safe interface definition

  1. Mention context and globals for preconditions.
  Part of Bugzilla 24098 - Safe variable can be initialized from `@system`
  static constructor.

  2. `@trusted` functions can create unsafe values/aliasing so long as they
  are not accessible from `@safe` code.

https://github.com/dlang/dlang.org/pull/3789

--
March 30
https://issues.dlang.org/show_bug.cgi?id=24098

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dlang.org pull request #3789 "[spec/function] Fix Safe Interface definition" was merged into master:

- e3fd3f0e5bebb9884e05a1bc9031176a682df365 by Nick Treleaven:
  [spec] Fix Safe interface definition

  1. Mention context and globals for preconditions.
  Part of Bugzilla 24098 - Safe variable can be initialized from `@system`
  static constructor.

  2. `@trusted` functions can create unsafe values/aliasing so long as they
  are not accessible from `@safe` code.

https://github.com/dlang/dlang.org/pull/3789

--