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();
}