Summary: Assert expressions shouldn't have side effects
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from simendsjo <> 2011-05-29 08:01:34 
PDT --- says "It is
an error if the expression contains any side effects that the program depends

This is not enforced by the compiler though:

module assert_sideeffect;
bool b;
bool f() { b = !b; return b; }
void main() {
    assert(f()); // oops.. changes b in debug mode
    if(!b) { // true only in release

dmd -g -w -wi -debug -run assert_sideeffect
// no output

dmd -g -w -wi -release -run assert_sideeffect
object.Error: assert(0) or HLT instruction

Bearophile suggested:
"In D there are pure functions, so I think it's not too much hard for it to
tell apart when the contents of an assert() are pure or not.
My opinion is that the D compiler has to enforce purity inside assert(), to
avoid bugs.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to