Comment #0 by dlang-bugzilla — 2014-09-09T10:20:37Z
__gshared access in @safe code is normally not allowed. But this compiles:
///////// test.d ////////
__gshared int var;
void f(int i = var) @safe
{
}
void main() @safe
{
f();
}
/////////////////////////
Comment #1 by bugzilla — 2016-06-07T08:44:15Z
The unsafe-ness of a default argument is in the caller side, not the function side. The error should be caught in main(), not in the compilation of f().
Still a bug, though.
Comment #2 by bugzilla — 2016-06-25T00:42:05Z
Unfortunately, fixing this is going to be a bit difficult. Safety checks are done during the semantic pass, not an add-on. The semantic pass for default args are run in the context of the function declaration, not the function call site, meaning the safety checks are not included in the semantic analysis of the function call site.
Comment #3 by pro.mathias.lang — 2020-11-09T00:22:24Z
Indeed, and this applies to most attributes (`nothrow` excepted). Marking as duplicate.
*** This issue has been marked as a duplicate of issue 11048 ***