Assert allowed to have side effects?

Stewart Gordon smjg_1998 at yahoo.com
Mon May 30 16:34:02 PDT 2011


On 29/05/2011 14:03, bearophile wrote:
> Stewart Gordon:
>
>> There are places where the spec fails to make a clear distinction between illegal code and
>> incorrect code that the compiler may reject if it's smart enough.
>
> 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.

Only if purity rules are relaxed.  AIUI, one of the restrictions at the moment is that in 
a pure function only immutable data can be accessed.  As long as this restriction remains 
in place, adding the restriction of purity to asserts would erode their usefulness.

Stewart.


More information about the Digitalmars-d-learn mailing list