[Issue 9450] New: make assert an implicit "version (assert)"

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 4 04:39:48 PST 2013


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

           Summary: make assert an implicit "version (assert)"
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: monarchdodra at gmail.com


--- Comment #0 from monarchdodra at gmail.com 2013-02-04 04:39:47 PST ---
With the new conditional "version(assert)", we can write functions that are
dedicated to being used with asserts, and have them only compiled in when there
are actually asserts.

The problem is that the assert itself is still compiled in, verified, then
removed.

Because of this, asserts that use code that is compiled in with asserts fails
to compile. This forces the user to use a "version(assert) assert(foo());"
semantic.

Example:

//----
void main()
{
    //This works
    version(assert) assert(foo());

    //But this doesn't
    assert(foo); //main.d(7)
}

version(assert)
{
    bool foo()
    {
      return true;
    }
}
//----
rdmd -release main.d
//----
main.d(7): Error: undefined identifier foo
//----

I'd like the for assert to be enhanced to have the same semantics as if it was
actually in a "version(assert)" block. It's the logical behavior for it
anyways...

For a real world example, I had this pull for std.container.Array:
https://github.com/D-Programming-Language/phobos/pull/878/files
It streamlined error checking with dedicated functions.

I realized afterwards that the code does not compile in -release.
I now have to either:
- use "version(assert) assert(...);"
- Copy paste/mixin a ton of code.

IMO, both solutions are inferior to just having the assert being version'ed
out. I can work around the problem, but it's one of those little things that
makes everything smother when it works.

-- 
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