digitalmars.D.bugs - [Issue 8603] New: Member access operator doesn't always dereference the pointer it's operating on
- d-bugmail puremagic.com (67/67) Aug 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8603
- d-bugmail puremagic.com (58/58) Aug 31 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8603
- d-bugmail puremagic.com (10/10) Sep 03 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8603
- d-bugmail puremagic.com (7/8) Sep 04 2012 That's fixed by simply making using UFCS illegal when there function is
- d-bugmail puremagic.com (14/14) Sep 04 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8603
http://d.puremagic.com/issues/show_bug.cgi?id=8603 Summary: Member access operator doesn't always dereference the pointer it's operating on Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: tommitissari hotmail.com --- Comment #0 from Tommi <tommitissari hotmail.com> 2012-08-31 01:48:32 PDT --- struct S1 { int _value = 42; void fun() { ++_value; } } void fun(ref S1 s1) { s1._value += 1000; } void fun(ref S1* ptr1) { ++ptr1; } ///////////////////////////// struct S2 { int _value = 42; } void fun(ref S2 s2) { ++s2._value; } void fun(ref S2* ptr2) { ++ptr2; } ///////////////////////////// struct S3 { int _value = 42; } void fun(ref S3 s3) { ++s3._value; } void main() { auto ptr1 = new S1(); ptr1.fun(); // OK: calls member (*ptr1).fun() auto ptr2 = new S2(); ptr2.fun(); // WRONG: calls .fun(ptr2) // should call .fun(*ptr2) auto ptr3 = new S3(); ptr3.fun(); // ERROR: function main.fun (ref S3 s3) is // not callable using argument types (S3*) // Should call .fun(*ptr3) } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8603 Maxim Fomin <maxim maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim maxim-fomin.ru --- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2012-08-31 09:50:15 PDT --- I agree with current dmd behavior described here. UFCS purpose was to rewrite expression "obj.method(args)" to "method(obj, args)" and it was not intended to allow to call "void fun(ref S2 s2)" instead of "void fun(ref S1* ptr1)" with pointer argument. Equivalence of accessing member through pointer or directly through object (absence of -> operator) should happen only in cases when some actual member is accessed (to emphasize: equivalence of access, not equivalence of pointer and not-pointer types). In case of UFCS there is no member accessing and semantic need not be same. If your request to change behavior would be accepted, following problem arise: import std.stdio; struct S {} void foo(S s) { writeln("."); } void foo(S* ptr) { writeln("->"); } void main() { auto s = new S(); s.foo(); // currently prints "->", would print "." } If first function argument would be changed, the output would be also unintentionally changed. This is unexpected and contradicts to usual overloading rules. What I am afraid of, is that it would be possible to call function expected object value with implicitly converted (dereferenced) to value pointer. Moreover, this implicit pointer to type conversion would occur in some limited cases where function is called if it is a member of that type. Consider following code: import std.stdio; void foo(int i) { writeln("."); } void foo(int* i) { writeln("->"); } void main() { int* i; foo(i); // good i.foo(); // bug } In this case what actually would happen is: (unexpected) conversion of pointer type to non-pointer type requires (unintentional) pointer dereference which would result in segfault. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 31 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8603 Maxim Fomin <maxim maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jmdavisProg gmx.com --- Comment #2 from Maxim Fomin <maxim maxim-fomin.ru> 2012-09-03 20:27:18 PDT --- *** Issue 8616 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 03 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8603 --- Comment #3 from Jonathan M Davis <jmdavisProg gmx.com> 2012-09-04 11:06:28 PDT ---If your request to change behavior would be accepted, following problem arise:That's fixed by simply making using UFCS illegal when there function is overloaded on both S and S*. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 04 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8603 Jonathan M Davis <jmdavisProg gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |DUPLICATE --- Comment #4 from Jonathan M Davis <jmdavisProg gmx.com> 2012-09-04 11:09:40 PDT --- I know that this report was created before issue# 8616 (and I missed this one when I created it), but I think that the description in 8616 is much better, so I'm going to close this one in favor of that one. *** This issue has been marked as a duplicate of issue 8616 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 04 2012