Bug 7980 – Stack overflow / recursive expansion with alias this

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-24T13:17:00Z
Last change time
2013-03-06T21:23:45Z
Keywords
ice, pull
Assigned to
nobody
Creator
rswhite4

Comments

Comment #0 by rswhite4 — 2012-04-24T13:17:05Z
The code below prints "not_null2.d(45): Error: template instance not_null2.assumeNotNull!(Foo) recursive expansion". If i write in line 45 "return NotNull!(Foo)(this);", instead of "return assumeNotNull(this);", i'm getting this error: "Stack overflow". In my opinion it should work. import std.stdio; struct NotNull(T : Object) { private: T _obj; public: @disable this(); @disable this(typeof(null)); this(T obj) { assert(obj !is null); this._obj = obj; } inout(T) get() inout { return this._obj; } alias get this; } NotNull!(T) assumeNotNull(T : Object)(T t) { return NotNull!(T)(t); } @property NotNull!(T) createNotNull(T : Object)() { T t = new T(); return assumeNotNull(t); } class Foo { public: void say() { writeln("Foo"); } NotNull!(Foo) get() { return assumeNotNull(this); } alias get this; } void foo(Foo f) { f.say(); } void bar(NotNull!(Foo) nf) { nf.say(); } void main() { Foo f1 = new Foo(); NotNull!(Foo) nf1 = new Foo(); foo(f1); bar(nf1); foo(nf1); bar(f1); }
Comment #1 by k.hara.pg — 2012-06-27T19:43:54Z
Comment #2 by github-bugzilla — 2013-03-06T18:04:06Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ef9a73ca6719172c51b1abf0b94d238d1df87674 Merge pull request #1028 from 9rnsr/fix_aliasthis Issue 7437,7980,8053 - Partial fix for stack overflow with recursive alias this