Bug 6358 – Segfault when using an member template (not a template instance) in an expression.
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-20T14:15:00Z
Last change time
2013-10-05T16:46:02Z
Keywords
ice
Assigned to
nobody
Creator
kennytm
Comments
Comment #0 by kennytm — 2011-07-20T14:15:47Z
Test case:
-------------------------------------------
struct S6358 {
double peek(T)(int x) {
return 0;
}
}
void bug6358a() {
S6358 s;
cast(void) (s.peek is &s); // <-- (a)
}
void bug6358b() {
S6358 s;
cast(void) (s.peek + &s); // <-- (b)
}
void bug6358c() {
S6358 s;
s.peek += 1; // <-- (c)
}
-------------------------------------------
The ICE in (a) happens at:
Expression *BinExp::typeCombine(Scope *sc)
{
Type *t1 = e1->type->toBasetype();
Type *t2 = e2->type->toBasetype(); // <-- this line, e2->type == NULL
if (op == TOKmin || op == TOKadd)
{
The ICE in (b) happens at:
AggregateDeclaration *isAggregate(Type *t)
{
t = t->toBasetype(); // <-- this line, t == NULL
if (t->ty == Tclass)
{
The ICE in (c) happens at:
int CallExp::isLvalue()
{
// if (type->toBasetype()->ty == Tstruct)
// return 1;
Type *tb = e1->type->toBasetype(); // <-- the line, e1->type == NULL
Comment #1 by lovelydear — 2012-04-20T15:51:22Z
The test case doesn't compile on 2.059 Win32, but doesn't crash.
PS E:\DigitalMars\dmd2\samples> rdmd -w --main bug.d
bug.d(8): Error: cannot resolve type for s.peek(T)
bug.d(8): Error: incompatible types for ((s.peek(T)) is (& s)): '_error_' and 'S6358*'
bug.d(12): Error: cannot resolve type for s.peek(T)
bug.d(12): Error: incompatible types for ((s.peek(T)) + (& s)): '_error_' and 'S6358*'
bug.d(16): Error: cannot resolve type for s.peek(T)
PS E:\DigitalMars\dmd2\samples>
Comment #2 by bugzilla — 2013-10-05T16:46:02Z
With dmd 2.064 head:
test.d(8): Error: cannot resolve type for s.peek(T)(int x)
test.d(12): Error: cannot resolve type for s.peek(T)(int x)
test.d(16): Error: cannot resolve type for s.peek(T)(int x)
which looks correct.