Currently, attributes such as @safe, pure and nothrow are automatically inferred for function templates. They should also be inferred for methods of struct/class templates and for Voldemort types. Test case: struct S1 { void foo(T)() { } } struct S2(T) { void foo() { } } auto makeS3(T)() { struct S3 { void foo() { } } return S3(); } void main() @safe pure nothrow { // Works S1 s1; s1.foo!int(); // Compilation failure S2!int s2; s2.foo(); // Compilation failure auto s3 = makeS3!int(); s3.foo(); } This currently prevents large parts of Phobos from being used in @safe/pure/nothrow contexts, and it prevents parts of Phobos from being marked as such. It also blocks some changes to std.path that I have in the pipeline, because I want to reimplement a function in terms of std.algorithm functions without removing its current attributes (as this would be a breaking change). A workaround (which is *not* feasible for use in Phobos) is to make the methods themselves trivial templates: struct S2(T) { void foo()() { } }
Yeah, I think Kenji also mentioned he'd like to see this implemented.
Attributes should also be inferred for functions nested in function templates: void foo(T)() { void inner() { } inner(); } void main() @safe pure nothrow { // Compilation failure: foo!int(); }
https://github.com/D-Programming-Language/dmd/pull/2259
*** Issue 10878 has been marked as a duplicate of this issue. ***
This bug makes std.range.chain unusable in pure code.
https://github.com/D-Programming-Language/dmd/pull/2832
*** Issue 11556 has been marked as a duplicate of this issue. ***
*** Issue 11866 has been marked as a duplicate of this issue. ***
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/237bb420c70fb6099dcedf94e7d9ed959a33e1fe fix Issue 10329 - Attributes not inferred for indirectly templated methods https://github.com/D-Programming-Language/dmd/commit/ebae884d9cd3a0c4ebf3c1b129654ba31ee0e73f Merge pull request #2832 from 9rnsr/fix10329 Issue 10329 - Attributes not inferred for indirectly templated methods