www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9450] New: make assert an implicit "version (assert)"

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: monarchdodra gmail.com



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: -------
Feb 04 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9450


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com,
                   |                            |k.hara.pg gmail.com



10:05:57 PST ---
CC'ed Kenji. 

 Kenji: I think all that's required here is to return early in
'AssertExp::semantic' if 'global.params.release' is true, e.g.:

Expression *AssertExp::semantic(Scope *sc)
{
    if (global.params.release)
    {
        type = Type::tvoid;
        return this;
    }

    // ...
}

It seems to work for this simple case. Would this be ok?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 04 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9450


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com



10:11:40 PST ---
https://github.com/D-Programming-Language/dmd/pull/1614

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