[Issue 8709] toLower on alias this

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 23 03:39:54 PDT 2012


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


Jonathan M Davis <jmdavisProg at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg at gmx.com
          Component|Phobos                      |DMD


--- Comment #1 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-09-23 03:40:50 PDT ---
Reduced test case:

struct S
{
    alias value this;
    string value;
}

void main ()
{
  auto s = S("hello");
  char[] arr = "world".dup;
  s = cast(S)"other";
  s = cast(S)arr;
}

The cast from string to S works, but the cast from char[] to S does not, in
spite of the fact that their only difference is constness.

However, the fact that this came up with std.string.toLower just highlights how
error-prone it is to use alias this with templated functions. It's insanely
easy to have template constraints which pass just fine due to the presense of
alias this but then fail to actually compile or which behave bizarrely due to
when conversions do and don't happen. I don't know what the solution to that is
though.

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