Bug 10329 – Attributes not inferred for indirectly templated methods

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-10T23:04:00Z
Last change time
2014-01-05T16:34:31Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2013-06-10T23:04:32Z
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()() { } }
Comment #1 by andrej.mitrovich — 2013-06-11T07:25:06Z
Yeah, I think Kenji also mentioned he'd like to see this implemented.
Comment #2 by bugzilla — 2013-06-14T12:27:31Z
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(); }
Comment #3 by henning — 2013-06-25T13:20:38Z
Comment #4 by monarchdodra — 2013-08-24T10:24:04Z
*** Issue 10878 has been marked as a duplicate of this issue. ***
Comment #5 by hsteoh — 2013-10-16T14:32:21Z
This bug makes std.range.chain unusable in pure code.
Comment #6 by k.hara.pg — 2013-11-19T23:00:49Z
Comment #7 by monarchdodra — 2013-11-19T23:09:08Z
*** Issue 11556 has been marked as a duplicate of this issue. ***
Comment #8 by k.hara.pg — 2014-01-05T00:43:42Z
*** Issue 11866 has been marked as a duplicate of this issue. ***
Comment #9 by github-bugzilla — 2014-01-05T15:35:56Z
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