Bug 678 – Compiler accepts, for a function T[] t(), t().ptr but not t.ptr

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-12-11T22:51:00Z
Last change time
2014-02-15T13:19:34Z
Keywords
rejects-valid, spec
Assigned to
bugzilla
Creator
davidl
Blocks
3107

Comments

Comment #0 by davidl — 2006-12-11T22:51:16Z
void[] t(){return null;} void main() { void* m; m=t().ptr; //compiles m=t.ptr; // fails, i'm worry about if let it through , maybe we will have buggy code. but due to D's documentation this should be compiled }
Comment #1 by davidl — 2006-12-11T23:32:22Z
h3r3tic imo it shouldnt work... if it worked, one would assume it to work for delegates as well. but delegates support the .ptr property so it couldnt work with them.
Comment #2 by davidl — 2007-09-15T09:51:15Z
previous code compiles with DMD 1.021, don't know if any ealier version fixes the behavior, while the following ambiguous is related to this change (mentioned by h3) void[] t(){return null;} class v { void[] k(){return null;}; } void main() { void[] delegate() dg; auto inst= new v; dg= &inst.k; assert(dg().ptr is null); assert(dg.ptr is null); void* m; m=t().ptr; //compiles m=t.ptr; // fails, i'm worry about if let it through , maybe we will have buggy code. but due to D's documentation this should be compiled }
Comment #3 by sandford — 2009-08-03T19:22:04Z
Both examples compile in D 2.031. Should this be marked as resolved?
Comment #4 by jarrett.billingsley — 2009-08-03T20:12:06Z
(In reply to comment #3) > Both examples compile in D 2.031. > > Should this be marked as resolved? The second example *compiles* but the second assertion fails.
Comment #5 by witold.baryluk+d — 2010-02-05T06:27:27Z
The problem with this code is that compiler doesn't know if you ask for: 1) a pointer of the base of the void[] array returned from t (used as property) 2) or a pointer of the t function/delegatel
Comment #6 by bearophile_hugs — 2010-11-26T13:55:18Z
This situations will be partially cleaned up when functions/delegates calls will require (). The specs need to specify what's the behaviour of using the .ptr of a @property delegate that returns an array (or that returns anything that has a ptr field): void main() { @property int[] delegate() bar1 = { return [1, 2]; }; struct Foo { int* ptr; } @property Foo delegate() bar2 = { return Foo(); }; auto x1 = bar1.ptr; auto x2 = bar2.ptr; }
Comment #7 by github-bugzilla — 2012-01-21T11:37:16Z
Comment #8 by bugzilla — 2012-01-21T11:38:24Z
Spec clarified.