@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.
What do you mean by "doesn't work ?" This code compiles on 2.059, but I'm not sure what you wanted to test.
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.
https://github.com/dlang/dmd/pull/9076
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
@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
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
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