[Issue 15125] Explicit pure needed even though pure: at the top of the file

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 28 09:55:03 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=15125

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
Although I cannot find any documentation about it, from what my experience
using pure:, safe:, extern(something):, nogc:, nothrow: works only for
top-level declaration (does not include the inner scopes of
aggregateDeclarations).

In your specific case pure and safe are applied to the MyExceptionClass but
since safe and pure do not make sense for classes, they are silently ignored
(not propagated to member functions).

I have no idea if this is the intended behavior or not, but in my opinion,
dmd's policy to silently ignore attributes when they do not make sense is not a
good one.

Other notable cases:

extern(C) class A {} // compiler accepts it and ignores extern(C) 

pure class A {}      // again no problem, but pure is not propagated to A's 
                     // methods

@safe class A {}     // ditto

The explanation for this is that you can use `$attribute`: at the top of the
module and only the declarations that make sense in conjunction with that
attribute will be affected and changing this to actually issuing an error for
those that don't would break too much code. I tried doing this for `extern(C)
class` and look at the result [1].

In conclusion, this will most likely be closed as WONTFIX.

[1] https://github.com/dlang/dmd/pull/7229

--


More information about the Digitalmars-d-bugs mailing list