Bug 5218 – Can't implicitly convert from "abc"w to wchar[3]
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-11-15T13:09:00Z
Last change time
2015-06-09T05:11:49Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2010-11-15T13:09:39Z
... though you can with char. This code also worked in D1.
---
void bug5218c(char [3] s) {}
void bug5218w(wchar [3] s) {}
void bug5218d(dchar [3] s) {}
void main()
{
bug5218c("abc");
bug5218w("abc"w);
bug5218d("abc"d);
}
Comment #1 by clugdbug — 2010-11-15T15:36:06Z
PATCH: This is because "abc"w and "abc"d are committed types. If the type is committed, implicit conversions are not performed at all. But this is wrong: they should still allow const/immutable conversions.
Index: cast.c
===================================================================
--- cast.c (revision 755)
+++ cast.c (working copy)
@@ -449,8 +449,6 @@
printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
toChars(), committed, type->toChars(), t->toChars());
#endif
- if (!committed)
- {
if (!committed && t->ty == Tpointer && t->nextOf()->ty == Tvoid)
{
return MATCHnomatch;
@@ -471,7 +469,8 @@
((TypeSArray *)t)->dim->toInteger())
return MATCHnomatch;
TY tynto = t->nextOf()->ty;
- if (tynto == Tchar || tynto == Twchar || tynto == Tdchar)
+ if (tynto == tyn) return MATCHexact;
+ if (!committed && (tynto == Tchar || tynto == Twchar || tynto == Tdchar))
return MATCHexact;
}
else if (type->ty == Tarray)
@@ -480,7 +479,8 @@
((TypeSArray *)t)->dim->toInteger())
return MATCHnomatch;
TY tynto = t->nextOf()->ty;
- if (tynto == Tchar || tynto == Twchar || tynto == Tdchar)
+ if (tynto == tyn) return MATCHexact;
+ if (!committed && (tynto == Tchar || tynto == Twchar || tynto == Tdchar))
return MATCHexact;
}
case Tarray:
@@ -497,13 +497,13 @@
case Tchar:
case Twchar:
case Tdchar:
- return m;
+ if (!committed)
+ return m;
}
break;
}
}
}
- }
return Expression::implicitConvTo(t);
#if 0
m = (MATCH)type->implicitConvTo(t);