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

           Summary: Purity of assert's second parameter
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: dran...@gmail.com


--- Comment #0 from Nicolas Sicard <dran...@gmail.com> 2012-05-08 02:39:16 PDT 
---
Calling impure functions in the second parameter of an assert statement within
the body of a pure pure is an error, even in release mode. Since such a call is
just about displaying an error message, should purity be checked here? Idem for
static asserts.  Maybe it is the same for 'nothrowness' (I didn't try).

Example:
---
import std.conv : text; // text is not pure

pure int foo(int value) {
    assert(value <= 10, text(value, " is greater than ", 10)); // Error: pure
function 'foo' cannot call impure function 'text'
    return value;
}

pure int foo2(int value) {
    debug assert(value <= 10, text(value, " is greater than ", 10)); // OK
    return value;
}

pure T bar(T)(T value) {
    static assert(T.sizeof == 4, text("Bad type size: ", T.sizeof)); // Error:
pure function 'bar' cannot call impure function 'text'
    return value;
}

void main() {
    int f = foo(42);
    int f2 = foo2(42);
    auto b = bar(42L);
}
---

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

Reply via email to