www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12028] New: Disallow side effects in asserts

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12028

           Summary: Disallow side effects in asserts
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



I suggest to statically disallow code like this, that is to disallow side
effects in assert(), that are source of bugs (because the code can act
differently in release mode):


int foo(ref int y) pure nothrow {
    return y++;
}
void main() {
    int x;
    assert(++x);
    assert(foo(x));
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 29 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12028


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



01:49:47 PST ---
It might be controversial, however I do remember someone actually running into
this bug in #d last year.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12028


Dylan Knutson <tcdknutson gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tcdknutson gmail.com



PST ---
Andrej, I believe that was me! It would have been nice to have that code
checked for side effects in assert statements. I'm in support of this
enhancement request.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 03 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12028




A discussion thread:
http://forum.dlang.org/thread/yzopesnnlgidhelsrrci forum.dlang.org


A problem raised by Brad Roberts:

 I have one semi-large code base where I validate the locking semantics
 by adding assert(!lock.try_acquire)'s.  That's clearly a side effect,
 but also clearly should never have one if the code is correct.
And an answer by Marco Leise:
 Basically lock.try_acquire is pure when it returns false, and if not,
 the program is terminated anyways so it doesn't make a difference.
-- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 03 2014