[Issue 2702] Struct initialisation silently inserts deadly casts
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 25 01:06:48 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2702
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #7 from Don <clugdbug at yahoo.com.au> 2009-09-25 01:06:47 PDT ---
Here's a revised patch, same place (VarDeclaration::semantic in declaration.c,
around line 1083). Replace the existing code with this version, which
explicitly allows opCall and NOTHING ELSE:
---
// Dynamic initialization uses static opCall.
if (!ei->exp->implicitConvTo(type))
{ // Look for opCall
if (search_function(sd, Id::call))
{ // Rewrite as e1.call(arguments)
Expression * eCall = new DotIdExp(loc, e1, Id::call);
ei->exp = new CallExp(loc, eCall, ei->exp);
}
}
---
This passes everything in the DMD test suite, except for one line in one test
(xtest46.d, test30) which I believe to be broken. I don't think that all of the
opDot() and 'alias this' possibilities are tested in the test suite, however.
Here's a tiny test which concisely tests the main features:
struct A { char [] a; }
struct B { long x; }
struct C { int a;
static C opCall(int b) { C q; q.a=b; return q; }
}
static assert(!is(typeof( (){ A s; B q = s; })));
static assert(!is(typeof( (){ B x =1L; })));
static assert(is(typeof( (){ C g = 7; })));
static assert(is(typeof( (){ C g = 7; C h = g;})));
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list