Bug 7616 – aggregates don't inherit pure, @nogc, nothrow from outer scope

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-29T23:02:12Z
Last change time
2024-12-13T17:58:45Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Martin Nowak
See also
https://issues.dlang.org/show_bug.cgi?id=19472
Moved to GitHub: dmd#18420 →

Comments

Comment #0 by code — 2012-02-29T23:02:12Z
@safe: // works pure nothrow: // doesn't work struct Foo1 { void bar() {} } struct Foo2 { pure nothrow: // redundant void bar() {} } pragma(msg, typeof(Foo1.bar)); pragma(msg, typeof(Foo2.bar)); @property doesn't work either. -------- I liked Don's idea of an attribute stack in the parser to get rid of these inconsistencies.
Comment #1 by lovelydear — 2012-04-20T02:46:05Z
What do you mean by "doesn't work ?" This code compiles on 2.059, but I'm not sure what you wanted to test.
Comment #2 by hsteoh — 2014-08-18T20:02:04Z
Gah, this is a mess. On git HEAD, the original produces this output: ------ @safe void() pure nothrow @safe void() ------ which seems to indicate that "pure nothrow:" has no effect. Commenting out the "pure nothrow:" line in Foo2 produces: ------ @safe void() @safe void() ------ So basically, "pure nothrow:" doesn't work at all.
Comment #3 by dhasenan — 2018-12-13T21:43:09Z
Comment #4 by dhasenan — 2018-12-14T20:11:50Z
The spec at https://dlang.org/spec/attribute.html says: attribute: // affects all declarations until the end of // the current scope The obvious interpretation is that any declaration between `attribute:` and the end of the current scope should have `attribute` applied. This includes nested declarations. A version that doesn't include nested declarations would say something like "affects all declarations within the current scope after `attribute:`", ideally with clarification about nested scopes. If there were any such text, then @safe would need to *not* propagate for consistency, *or* there would need to be other text saying that @safe propagates differently (which currently there isn't). More illustrative test case: --- nothrow pure { struct Foo { int b() { return 1; } } } int k() nothrow pure { Foo foo; return foo.b(); } --- Expected result: k() returns 1. Actual result: scratch.d(11): Error: pure function scratch.k cannot call impure function scratch.Foo.b scratch.d(11): Error: function scratch.Foo.b is not nothrow scratch.d(8): Error: nothrow function scratch.k may throw
Comment #5 by dlang-bot — 2024-08-03T13:53:37Z
@ntrel created dlang/dlang.org pull request #3893 "[spec] Improve attribute propagation docs" mentioning this issue: - [spec] Improve attribute propagation docs Part of Bugzilla 7616 - aggregates don't inherit pure nothrow from outer scope Add grammar heading. `@nogc`, `nothrow` and `pure` do not propagate inside aggregates. Add example. Add link to core.attribute. https://github.com/dlang/dlang.org/pull/3893
Comment #6 by dlang-bot — 2024-08-03T15:39:54Z
dlang/dlang.org pull request #3893 "[spec] Improve attribute propagation docs" was merged into master: - d55c919d5de5e34235c24f40eb734d54d40f83e1 by Nick Treleaven: [spec] Improve attribute propagation docs Part of Bugzilla 7616 - aggregates don't inherit pure nothrow from outer scope Add grammar heading. `@nogc`, `nothrow` and `pure` do not propagate inside aggregates. Add example. Add link to core.attribute. https://github.com/dlang/dlang.org/pull/3893
Comment #7 by robert.schadek — 2024-12-13T17:58:45Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18420 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB