[Issue 7616] aggregates don't inherit pure nothrow from outer scope
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 14 20:11:50 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=7616
Neia Neutuladh <dhasenan at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
--- Comment #4 from Neia Neutuladh <dhasenan at gmail.com> ---
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
--
More information about the Digitalmars-d-bugs
mailing list