digitalmars.D.bugs - [Issue 10008] New: Inconsistent inference of template and non-template function attributes
- d-bugmail puremagic.com (37/37) Apr 29 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10008
- d-bugmail puremagic.com (14/14) Apr 29 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10008
- d-bugmail puremagic.com (10/10) Apr 29 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10008
- d-bugmail puremagic.com (24/29) Apr 29 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10008
- d-bugmail puremagic.com (11/11) Apr 29 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10008
http://d.puremagic.com/issues/show_bug.cgi?id=10008 Summary: Inconsistent inference of template and non-template function attributes Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: maxim maxim-fomin.ru --- struct S() { void foo(){} } struct Z { void foo(){} } void main() safe { auto x = &Z.foo; auto y = &S!().foo; pragma(msg, typeof(x)); pragma(msg, typeof(y)); x(); y(); } Member function of templated struct is deduced to be pure nothrow safe while non-templated struct function is not. Either both should be rejected or none of them. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 29 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10008 This is a new D feature from 2.063. For the *instantiated* non-virtual member functions, compiler now infers their function attributes as same as normal template functions. This is useful template based structures, such as std.algorithm and std.range. Now, most of ranges and algorithms would work in safe/pure/nothrow functions. import std.algorithm, std.range; void main() safe pure nothrow { auto r = [1,2,3].map!(a => a*2).retro; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 29 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10008 --- OK, this explains why function from templated struct is deduced to have all attributes. But this tells nothing about another case. I understand that Z.foo is not required to be safe/pure/nothrow because it isn't marked as such, but on the other hand S.foo() is also not marked and clearly there is contradiction here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 29 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10008OK, this explains why function from templated struct is deduced to have all attributes. But this tells nothing about another case. I understand that Z.foo is not required to be safe/pure/nothrow because it isn't marked as such, but on the other hand S.foo() is also not marked and clearly there is contradiction here.Short answer is that it is just same as the difference between: void foo() {} and void bar()() {} Both don't have attributes explicitly, but bar would be inferred to safe/pure/nothrow when it is instantiated. --- There is an essential difference between template functions and non-template ones. For the former, the actual function attributes of instantiated code is not pre-deterministic. Ultimately, it would depend on the arguments which is given on the template parameters. Attribute inference for the instantiated functions is necessary for making function attributes more convenient. On the other hand, the functions out of the template declaration should be "as is". You can hide the function body in the library file for the separate compilation, and just only declaring function signatures in di file. Therefore, we cannot/should not apply attribute inference for normal functions. The contradiction you feel comes from the essential difference that I described in above. Thanks. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 29 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10008 Maxim Fomin <maxim maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID --- I see, mark it as RESOLVED INVALID. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 29 2013