Bug 3775 – Segfault(cast.c): casting no-parameter template function using property syntax

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2010-02-05T18:36:00Z
Last change time
2014-02-15T13:13:12Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
b.helyer

Comments

Comment #0 by b.helyer — 2010-02-05T18:36:45Z
Apologies if this is a duplicate, I couldn't see anything *obvious*. I'm sure this is invalid code, but I got on to doing this (don't ask): --- module segfault; import std.stdio; void main() { foreach (line; cast(string) stdin.byLine) {} } --- Which leads to: --- $ dmd segfault Segmentation fault --- Needless to say, no object or executable file is produced.
Comment #1 by clugdbug — 2010-02-09T06:10:02Z
Reduced test case also segfaults on D1, even ancient ones like DMD0.175. struct Bug3775 { static int byLine()() { return 1; } } static assert( cast(int) Bug3775.byLine); Somehow, in DotIdExp::semantic, it has no type.
Comment #2 by clugdbug — 2010-02-09T11:28:25Z
ROOT CAUSE: This is an interaction between IFTI and property syntax. PATCH: At the end of CastExp::semantic, make sure that the function has a type. Index: expression.c =================================================================== --- expression.c (revision 373) +++ expression.c (working copy) @@ -7796,7 +7796,11 @@ // BUG: Check for casting array types, such as void[] to int*[] } - + if (!e1->type && e1->op==TOKdottd) + { + error("%s is a template and cannot be called with property syntax", e1->toChars()); + return new ErrorExp(); + } e = e1->castTo(sc, to); return e; } ===== Some similar cases cause the compiler to do strange things (see below), so I'm not completely satisfied with the patch. But let's just fix the segfault. struct Bug3775 { static int byLine()() { return 1; } } void main(){ auto xxx = Bug3775.byLine; } // accepted; xxx is an int. void main(){ int xxx = Bug3775.byLine; } // rejected: (Bug3775).byLine() has no value
Comment #3 by bugzilla — 2010-02-11T22:55:17Z
changeset 378 and 379
Comment #4 by Kosmonaut — 2010-02-12T11:46:05Z
Comment #5 by bugzilla — 2010-03-08T22:23:27Z
Fixed dmd 1.057 and 2.041