[Issue 7980] New: Stack overflow / recursive expansion with alias this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 24 13:16:03 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7980

           Summary: Stack overflow / recursive expansion with alias this
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: rswhite4 at googlemail.com


--- Comment #0 from rswhite4 at googlemail.com 2012-04-24 13:17:05 PDT ---
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);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list