Created attachment 554
patch to convert seg-v to assert
I'm getting a seg-v (not an assert) at expression.c:6255 from some bad template
code.
this is the test case:
http://www.dsource.org/projects/scrapple/browser/trunk/units/si2.d?rev=689
compile with "-unittest -version=BUG" to get error
compile with "-unittest" to get correct result.
attached is a patch that converts the seg-v to an assert.
Comment #1 by shro8822 — 2010-01-23T13:05:00Z
I forgot to mention; I tried to cut down the test case and it quit erroring.
Comment #2 by clugdbug — 2010-01-25T04:21:29Z
I can't reproduce the segfault. When compiling si2, I just get this:
------
si2.d(155): Error: Cannot interpret SIB!(__T5BatchVi1Vi1Vi0Vi1Vi0Vi1Vi0Vi1Vi0Vi1
Z,real) at compile time
si2.d(155): Error: Cannot interpret SIB!(__T5BatchVi1Vi1Vi0Vi1Vi0Vi1Vi0Vi1Vi0Vi1
Z,real) at compile time
si2.d(155): Error: template instance 'Batch!(LengthN,1,MassN,1,TimeN,1,TempN,1,C
urrentN,1)' is not a variable
si2.d(155): Error: no property 'LenD' for type 'int'
Comment #3 by shro8822 — 2010-01-25T10:32:24Z
What version of DMD? I got it with 2.039 on both windows and linux. Might it already be fixed in SVN?
Comment #4 by clugdbug — 2010-01-25T12:22:35Z
(In reply to comment #3)
> What version of DMD? I got it with 2.039 on both windows and linux. Might it
> already be fixed in SVN?
I can reproduce it now. I think I had the wrong rational.d.
Comment #5 by clugdbug — 2010-01-25T13:01:07Z
Reduced test case. Something to do with opDispatch.
======================
int crayon;
struct SIB(alias junk)
{
template Alike(V) {
enum bool Alike = Q == V.garbage;
}
void opDispatch(string s)() {
static assert(Alike!(SIB!(crayon)));
}
}
void main() {
SIB!(SIB!(crayon).E)(3.0);
}
Comment #6 by clugdbug — 2010-01-26T00:06:30Z
Cause: If global.errors && !global.gag, TemplateInstance::semantic doesn't set 'inst'. So this is a possible patch (not recommended) inside template.c:
{
if (!global.gag)
{
/* Trying to soldier on rarely generates useful messages
* at this point.
*/
fatal();
}
+ inst = this; // error recovery
return;
}
===
But, on the other hand, most other functions in expression.c only run ti->semantic() if there are global.errors.
So this patch to expression.c line 6252 may be better:
Expression *DotTemplateInstanceExp::semantic(Scope *sc)
{
#if LOGSEMANTIC
printf("DotTemplateInstanceExp::semantic('%s')\n", toChars());
#endif
Expression *eleft;
Expression *e = new DotIdExp(loc, e1, ti->name);
L1:
e = e->semantic(sc);
if (e->op == TOKdottd)
{
+ if (global.errors) return new ErrorExp();
DotTemplateExp *dte = (DotTemplateExp *)e;
TemplateDeclaration *td = dte->td;
The same problem occurs in mtype.c, line 6613, 7101, inside ::dotExp(), for structs and classes, and they should probably have the same fix.
(they shouldn't be running ti->semantic() if there are global errors).