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

           Summary: Combination of pure and nothrow result in a function
                    that does nothing
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: jmdavisp...@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisp...@gmx.com> 2010-11-09 02:31:20 
PST ---
import std.stdio;

struct Foo
{
    void add(T)(T value) pure nothrow
    {
        this.value += value;
    }

    this(int value)
    {
        this.value = value;
    }

    int value;
}

void main()
{
    auto foo = Foo(5);
    assert(foo.value == 5);

    foo.add(2);
    writeln(foo.value);
    assert(foo.value == 7);

    foo.add(3);
    writeln(foo.value);
    assert(foo.value == 10);

    foo.add(3);
    writeln(foo.value);
    assert(foo.value == 13);
}


If you remove either the pure _or_ the nothrow (or both) from add(), you get
this output:

7
10
13


However, if add() is both pure and nothrow, then you get an assertion failure:

5
core.exception.asserter...@test(25): Assertion failure
----------------
./test(onAssertError+0x2e) [0x808d40e]
./test(_d_assertm+0x16) [0x8085536]
./test(void test.__assert(int)) [0x80828d6]
./test(_Dmain+0x43) [0x807f7a7]
./test(extern (C) int rt.dmain2.main(int, char**)) [0x8085746]
./test(extern (C) int rt.dmain2.main(int, char**)) [0x80856a0]
./test(extern (C) int rt.dmain2.main(int, char**)) [0x808578a]
./test(extern (C) int rt.dmain2.main(int, char**)) [0x80856a0]
./test(main+0x96) [0x8085646]
/usr/lib32/libc.so.6(__libc_start_main+0xe6) [0xf75d7c76]
./test() [0x807f6a1]


For some reason, the combination of pure and nothrow results in the function
being a no-op. Personally, since I try to make as many functions nothrow and as
many functions pure as possible, this is a serious fly in the ointment of both
pure and nothrow.

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

Reply via email to