Bug 8504 – Template attribute inferrence doesn't work

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-03T21:28:00Z
Last change time
2013-01-23T16:58:46Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
issues.dlang

Comments

Comment #0 by issues.dlang — 2012-08-03T21:28:45Z
This code import std.stdio; import std.traits; void func(R)(R range) { } void main() { pragma(msg, mangledName!(func!string)); static assert(functionAttributes!(func!string) == FunctionAttribute.safe); } results in this output _D1y13__T4funcTAyaZ4funcFAyaZv y.d(11): Error: static assert (0u == cast(FunctionAttribute)1u) is false func is templatized and has _nothing_ in it, so it should be inferred as @safe, pure, and nothrow, but as evidenced by the name mangling and complete lack of function attributes, it has been marked with none of those. The fact that this _really_ basic function isn't inferring any attributes makes it seem likely that attributes aren't ever getting inferred for any functions. Certainly, nothing I've tried thus far has resulted in any attributes being inferred (including adding @safe function calls to func, so it's not related to the fact that func is empty). And this code didn't work in the version of dmd when attribute inferrence was supposedly introduced (2.054) - or any version since then - so I have no idea what attribute inferrence is supposedly going on, since it's clearly not working. This is probably the same as bug# 8138, since that's specifically for attribute inferrence and Voldemort types, but if attribute inferrence isn't working for templates at all, then it's certainly not going to work for Voldemort types.
Comment #1 by k.hara.pg — 2012-08-28T09:42:34Z
https://github.com/D-Programming-Language/dmd/pull/1096 After semantic3 (semantics for function body code) done, typeof(func!string) returns 'pure nothrow @safe void(string)' because of the attribute inference, but it doesn't affect to its mangled name. That's a bug.
Comment #2 by k.hara.pg — 2013-01-21T23:04:02Z
A simple test case from: http://d.puremagic.com/issues/show_bug.cgi?id=6902#c6 cat > bug.d << CODE void a() { function void() { }(); } void b() { static void safe_nothrow() @safe nothrow pure { } auto f = &safe_nothrow; enum mangle = typeof(*f).mangleof; static assert(mangle == "FNaNbNfZv", mangle); } CODE dmd -c bug
Comment #3 by github-bugzilla — 2013-01-22T09:44:15Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f9d53eb403cbe29310cc501ad099acddb71cac75 fix Issue 8504 - Template attribute inferrence doesn't work https://github.com/D-Programming-Language/dmd/commit/6344a72ac2e2e597110891f7aed4b998d58f61fd Merge pull request #1096 from 9rnsr/fix8504 Issue 8504 - Template attribute inferrence doesn't work