[dmd-internals] Changes for pure, nothrow, and @safe done for the moment?
Jonathan M Davis
jmdavisProg at gmx.com
Sun Jun 26 21:29:33 PDT 2011
On 2011-06-26 21:20, Andrei Alexandrescu wrote:
> On 6/26/11 11:00 PM, Walter Bright wrote:
> > On 6/26/2011 8:50 PM, Andrei Alexandrescu wrote:
> >> On 6/26/11 10:34 PM, Walter Bright wrote:
> >>> I'm going to just back out the warning about pure functions with no
> >>> effect.
> >>
> >> Why? I think that would be a mistake. Roll in any way you wish (after
> >> fixing bugs and all), but do roll it it. There's absolutely never a
> >> good reason to call a pure function and ignore its result, unless you
> >> just want to keep the CPU warm.
> >
> > Because with pure & nothrow inference, it breaks a lot of code, for
> > example code like this:
> >
> > void foo(int i)
> > {
> > assert(i == 3);
> > }
>
> Hmmm... in this case, the function may terminate the program. Probably
> in such a case there should be no warning anyway - it does have an effect.
Except that any case where you need a delegate which specifically does nothing
(as Don suggested), it probably wouldn't have an assert, since it's not
intended to fail - just do nothing. And, of course, this particular function
can only fail if assertions are turned on, which makes it a bit funny.
Certainly, it would suck if this function weren't complained about when the
assertion was compiled in but failed to compile with -release.
Overall, it seems like warning about functions with no effect would make a lot
of sense, but it is looking like there are valid cases where you'd want to
have functions with no effect beyond being called, which makes warning about
any of them problematic. So, I don't know if we can have warnings about any of
them or not. Certainly, the situation with this is far more complicated than
it first appears.
- Jonathan M Davis
More information about the dmd-internals
mailing list