Implicit conversions through purity

Steve Teale steve.teale at britseyeview.com
Tue Apr 15 01:43:40 PDT 2014


On Monday, 14 April 2014 at 15:16:07 UTC, bearophile wrote:
> Steven Schveighoffer:
>
>> For that reason, I would disallow out parameters from casting 
>> implicitly.

A number of things perplex me here.

1) If I attempt to compile foo2() more or less as presented with 
2.065, the compiler tells me:

Error: '_adDupT' is not nothrow
Error: function 'mu.foo2' is nothrow yet may throw

What version is the discussion about?

2) If I have a simple program as follows, the compiler does not 
complain about me altering the value of global a.

import std.stdio;
string a = "aaa";

void foo2(in string s, ref string sOut) pure {
     auto s2 = s.dup;
     s2[0] = 'a';
     sOut = cast(string) s2; // Error: cannot implicitly convert
}

void main() {
{
    foo2("xyz", a);
    writeln(a);
}

3) Using a ref parameter for a pure function seems to me to be a 
clear indication of intended side effect. Wikipedia on pure 
functions says it's not allowed. Out does seem somehow different 
to me, since it's initial value is by definition throw-away.

Steve


More information about the Digitalmars-d-learn mailing list