Bug 12529 – Function/delegate type alias picks up @safe attribute from surrounding scope

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-06T11:48:00Z
Last change time
2016-06-14T23:14:30Z
Keywords
pull, rejects-valid, safe
Assigned to
nobody
Creator
bugzilla
See also
https://issues.dlang.org/show_bug.cgi?id=15142, https://issues.dlang.org/show_bug.cgi?id=12527

Comments

Comment #0 by bugzilla — 2014-04-06T11:48:27Z
Consider: @safe: alias F = void function(); This wrongly makes F an alias of "void function() @safe" rather than "void function()". Here is a test case which should compile, but which fails to do so: void foo() { } @safe: alias F = void function(); @trusted void bar(F f) { f(); } void main() { bar(&foo); } DMD says: bug.d(6): Error: function bug.bar (void function() @safe f) is not callable using argument types (void function())
Comment #1 by andrej.mitrovich — 2014-05-17T12:56:45Z
But this /is/ consistent with how extern(C) works. I think we should apply all attributes consistently, whatever the final decision is.
Comment #2 by k.hara.pg — 2014-05-17T14:05:36Z
Comment #3 by bugzilla — 2014-05-31T07:01:40Z
This is a behavior change, not a bug. Marked as enhancement.
Comment #4 by bugzilla — 2014-06-04T21:20:51Z
I think it *is* a bug. To me, the statement clearly says "make F an alias for void function()". Attributes should only apply to the declared symbol itself (and an alias obviously cannot be @safe; only functions can). Consider this: const: alias T = int; Should T now be an alias for int or const(int)? Currently, it is the former, as I think it should be.
Comment #5 by bugzilla — 2016-06-14T23:14:30Z
This is operating correctly. An alias should not be able to override the safety of the type, as in https://issues.dlang.org/show_bug.cgi?id=12527, but if it is the default it should be settable.