[Issue 5906] Just pre-conditions at compile-time when arguments are static

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 7 06:25:50 PST 2013


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


yebblies <yebblies at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies at gmail.com


--- Comment #7 from yebblies <yebblies at gmail.com> 2013-03-08 01:25:47 EST ---
I agree with Walter, nothing should be ctfe'd unless the code explicitly asks
for it.

However...

If the contracts are fairly simple, like in this function:

int func(int a, int b)
in
{
    assert(a + b != 12);
}
out(result)
{
    assert(result >= 20);
}
body
{
    return 15;
}

It would be possible for the compiler to use constant-folding (not ctfe) to
verify the assertions can pass, in the pre- and post-conditions.

eg.
func(3, 9); Error: function call func(3, 9) cannot pass precondition

or
Error: 'return 15' cannot pass postcondition

This can be done by converting precondition bodies to expressions then
const-folding them.  Non-trivial, but possible.

This only makes sense if we define violating a function's precondition as
invalid code.

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