Issue 13442 - __gshared default value allowed in @safe function signature
Summary: __gshared default value allowed in @safe function signature
Status: RESOLVED DUPLICATE of issue 11048
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords: accepts-invalid, safe
Depends on:
Blocks:
 
Reported: 2014-09-09 10:20 UTC by Vladimir Panteleev
Modified: 2020-11-09 00:22 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2014-09-09 10:20:37 UTC
__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 Walter Bright 2016-06-07 08:44:15 UTC
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 Walter Bright 2016-06-25 00:42:05 UTC
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 Mathias LANG 2020-11-09 00:22:24 UTC
Indeed, and this applies to most attributes (`nothrow` excepted). Marking as duplicate.

*** This issue has been marked as a duplicate of issue 11048 ***