Thread overview |
---|
November 11, 2008 [Issue 2448] New: template return by reference causes seg fault | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2448 Summary: template return by reference causes seg fault Product: D Version: 2.020 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: k-foley@onu.edu import std.stdio; ref T iif(T)(bool condition, ref T lhs, ref T rhs) { if ( condition ) return lhs; return rhs; } ref int int_iif(bool condition, ref int lhs, ref int rhs) { if ( condition ) return lhs; return rhs; } void main() { int a = 10, b = 11; int_iif(a<b, a, b) = 42; writeln("a = ", a, " and b = ", b); // a = 42 and b = 11 iif(a<b, a, b) = 52; // seg fault writeln("a = ", a, " and b = ", b); } -- |
January 26, 2009 [Issue 2448] template return by reference causes seg fault | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2448 andrei@metalanguage.com changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |major ------- Comment #1 from andrei@metalanguage.com 2009-01-25 23:32 ------- Adding another example and bumping this to major because it stops std.algorithm development dead in its tracks. template ElementType(R) { alias typeof({ R r; return r[0]; }()) ElementType; } bool empty(T)(in T[] a) { return !a.length; } void next(T)(ref T[] a) { assert(a.length); a = a[1 .. $]; } void retreat(T)(ref T[] a) { assert(a.length); a = a[0 .. $ - 1]; } T head(T)(T[] a) { assert(a.length); return a[0]; } ref T toe(T)(T[] a) { assert(a.length); return a[a.length - 1]; } struct Retro(R) { private: R _input; public: bool empty() { return _input.empty; } void next() { _input.retreat; } ElementType!(R) head() { return _input.toe; } } void main() { void test(int[] input) { foreach (e; Retro!(int[])(input)) { } } test([ 1 ]); } -- |
March 11, 2009 [Issue 2448] template return by reference causes seg fault | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2448 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #2 from bugzilla@digitalmars.com 2009-03-11 14:50 ------- Fixed dmd 2.025 -- |
Copyright © 1999-2021 by the D Language Foundation