Bug 5980 – foreach element of a type tuple of string literals is not implicitly convertible to immutable(char)*

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-05-11T11:03:00Z
Last change time
2015-06-09T05:13:45Z
Assigned to
nobody
Creator
Jesse.K.Phillips+D

Comments

Comment #0 by Jesse.K.Phillips+D — 2011-05-11T11:03:10Z
This worked in 2.052 but is failing to compile in the latest beta for 2.053. This is used by LuaD. struct A { int a; } void main() { foreach(field; __traits(allMembers, A)) { usefield(field); } } void usefield(const(char)* foo) { }
Comment #1 by Jesse.K.Phillips+D — 2011-05-11T11:09:35Z
Oh and the error message: break.d(7): Error: cannot implicitly convert expression (field) of type const(im mutable(char)[]) to const(char)*
Comment #2 by kennytm — 2011-05-11T11:23:13Z
(In reply to comment #0) > This worked in 2.052 but is failing to compile in the latest beta for 2.053. > This is used by LuaD. > > struct A { > int a; > } > void main() { > foreach(field; __traits(allMembers, A)) > { > usefield(field); > } > > } > > void usefield(const(char)* foo) { > } Why not use 'usefield(field.ptr)'? I don't think implicitly converting an array to a pointer is expected.
Comment #3 by Jesse.K.Phillips+D — 2011-05-11T11:33:58Z
Well I invasion the code being expanded to: void main() { usefield("a"); } Which is expected to implicitly convert to const(char)*
Comment #4 by andrei — 2011-05-11T12:29:17Z
The conversion of a string literal to a immutable(char)* has been disallowed, and for arguably good reasons. You may want to use a.ptr instead.
Comment #5 by kennytm — 2011-05-11T12:32:41Z
Actually it's a problem in foreach-ing a TupleExp of StringExp, not __traits. I changed the title to reflect that. ------------------------------------- template TypeTuple(T...) { alias T TypeTuple; } void main() { alias TypeTuple!"1" T; usefield(T[0]); // ok foreach (j; T) usefield(j); // error on 2.053 } void usefield(const(char)* foo) { } ------------------------------------- (Still, I think it's better to use .ptr then relying on it the implicit string literal -> pointer conversion.)
Comment #6 by kennytm — 2011-05-11T12:33:31Z
(In reply to comment #4) > The conversion of a string literal to a immutable(char)* has been disallowed, > and for arguably good reasons. You may want to use a.ptr instead. Really? Jesse's example in comment #3 is still compilable.
Comment #7 by andrei — 2011-05-11T12:44:19Z
I must be confused, sorry.
Comment #8 by yebblies — 2011-09-06T20:56:12Z
Fixed in 2.055 beta, probably the same as issue 6220.