Bug 3493 – Segfault(cast.c) Forward reference with type inference, D1 only.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2009-11-10T02:03:00Z
Last change time
2014-04-18T09:12:08Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2009-11-10T02:03:37Z
This is the second bug reported in bug 2080.
const bar = foo;
const int * foo = null;
Comment #1 by clugdbug — 2009-11-17T23:55:05Z
This doesn't segfault in D2 because in expression.c, VarExp::semantic(),
line 4152, the initializer part is commented out.
VarDeclaration *v = var->isVarDeclaration();
if (v)
{
+#if 0
if ((v->isConst() || v->isInvariant()) &&
type->toBasetype()->ty != Tsarray && v->init)
{
ExpInitializer *ei = v->init->isExpInitializer();
if (ei)
{
//ei->exp->implicitCastTo(sc, type)->print();
return ei->exp->implicitCastTo(sc, type);
}
}
+#endif
v->checkNestedReference(sc, loc);
#if DMDV2
Doing the same thing in D1 fixes this bug, and the DMD test suite still passes.
However I'm not sure why the code above is unnecessary.
Comment #2 by clugdbug — 2010-08-09T02:37:30Z
Here's a more minimal patch. It shouldn't be implicitly casting the initializer, if it hasn't run semantic on it yet.
expression.c, VarExp::semantic(), line 3955.
if (v)
{
if (v->isConst() && v->type && type->toBasetype()->ty != Tsarray && v->init)
{
ExpInitializer *ei = v->init->isExpInitializer();
- if (ei)
+ if (ei && ei->exp->type)
{
+ assert(ei->exp->type);
//ei->exp->implicitCastTo(sc, type)->print();
return ei->exp->implicitCastTo(sc, type);
}