Assert allowed to have side effects?

2011-05-29 Thread simendsjo
The documentation for assert, http://www.digitalmars.com/d/2.0/expression.html#AssertExpression, states that it's an error if the assert expression contains side effects, but it doesn't seem the compiler is enforcing this. module assert_sideeffect; bool b; bool f() { b = !b; return b; } void m

Re: Assert allowed to have side effects?

2011-05-29 Thread Stewart Gordon
On 29/05/2011 09:44, simendsjo wrote: The documentation for assert, http://www.digitalmars.com/d/2.0/expression.html#AssertExpression, states that it's an error if the assert expression contains side effects, but it doesn't seem the compiler is enforcing this. There are places where the spec

Re: Assert allowed to have side effects?

2011-05-29 Thread bearophile
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 asser

Re: Assert allowed to have side effects?

2011-05-29 Thread simendsjo
On 29.05.2011 15:03, bearophile wrote: 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. http://d.puremagic.com/issues/

Re: Assert allowed to have side effects?

2011-05-30 Thread Stewart Gordon
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

Re: Assert allowed to have side effects?

2011-05-30 Thread Jonathan M Davis
On 2011-05-30 16:34, Stewart Gordon wrote: > 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

Re: Assert allowed to have side effects?

2011-05-30 Thread David Nadlinger
On 5/31/11 1:34 AM, Stewart Gordon wrote: 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 th

Re: Assert allowed to have side effects?

2011-05-30 Thread bearophile
Stewart Gordon: > 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.