Bug 4371 – segfault(template.c) template tuple in is() expression
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-06-22T21:36:00Z
Last change time
2012-01-28T12:44:18Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
ellery-newcomer
Comments
Comment #0 by ellery-newcomer — 2010-06-22T21:36:24Z
The code:
struct s(T ...){
}
alias s!("hi!") t;
static if(is(t U == s!(U))){
}
void main(){
}
The fireworks:
Segmentation fault (core dumped)
on compile.
Comment #1 by clugdbug — 2010-11-26T00:44:26Z
There are two issues:
(1) deduceType() can return a tuple. This causes the segfault, because it isn't a type.
Fixing that stops the crash, but the code still doesn't work, because...
(2) Same as bug 5164: it shouldn't try to add the symbol twice. Exactly the same fix works here.
PATCH: expression.c, line 5185, IsExp::semantic().
----------
Lyes:
if (id)
{
- Dsymbol *s = new AliasDeclaration(loc, id, tded);
+ Dsymbol *s;
+ if (isTuple(tded))
+ s = new TupleDeclaration(loc, id, &(isTuple(tded)->objects));
+ else
+ s = new AliasDeclaration(loc, id, tded);
s->semantic(sc);
- if (!sc->insert(s))
- error("declaration %s is already defined", s->toChars());
if (sc->sd)
s->addMember(sc, sc->sd, 1);
+ else if (!sc->insert(s))
+ error("declaration %s is already defined", s->toChars());
}
//printf("Lyes\n");
return new IntegerExp(loc, 1, Type::tbool);
Lno:
//printf("Lno\n");
return new IntegerExp(loc, 0, Type::tbool);
Comment #2 by clugdbug — 2010-11-26T00:46:05Z
And the code was valid.
Comment #3 by clugdbug — 2010-11-26T12:35:50Z
There's something wrong with the patch.
This part breaks Phobos unit tests:
- if (!sc->insert(s))
- error("declaration %s is already defined", s->toChars());
if (sc->sd)
s->addMember(sc, sc->sd, 1);
+ else if (!sc->insert(s))
+ error("declaration %s is already defined", s->toChars());
Changing the first of those lines to:
if (!isTuple(tded) && !sc->insert(s))
error("declaration %s is already defined", s->toChars());
allows the test code to compile. But I don't really understand why it should be necessary. Possibly it's another bug which is being triggered.