mirror of
https://github.com/dlang/phobos.git
synced 2025-05-14 17:05:58 +03:00
fix Issue 7909 - to!(enum)(string) and to!(string)(enum) break when enum is integral
This commit is contained in:
parent
c27262cdb9
commit
52462bec6e
3 changed files with 31 additions and 25 deletions
|
@ -6,6 +6,7 @@ $(VERSION 060, ddd mm, 2012, =================================================,
|
||||||
)
|
)
|
||||||
|
|
||||||
$(LIBBUGSFIXED
|
$(LIBBUGSFIXED
|
||||||
|
$(LI $(BUGZILLA 7909): to!enum(string) and to!string(enum) break when enum is integral)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
$(VERSION 059, ddd mm, 2012, =================================================,
|
$(VERSION 059, ddd mm, 2012, =================================================,
|
||||||
|
|
26
std/conv.d
26
std/conv.d
|
@ -1048,21 +1048,23 @@ T toImpl(T, S)(S s)
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
|
debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
|
||||||
enum E { a, b, c }
|
|
||||||
assert(to! string(E.a) == "a"c);
|
|
||||||
assert(to!wstring(E.b) == "b"w);
|
|
||||||
assert(to!dstring(E.c) == "c"d);
|
|
||||||
|
|
||||||
enum F : real { x = 1.414, y = 1.732, z = 2.236 }
|
enum EU { a = 0, b = 1, c = 2 } // base type is unsigned
|
||||||
assert(to! string(F.x) == "x"c);
|
enum EI { a = -1, b = 0, c = 1 } // base type is signed (bug 7909)
|
||||||
assert(to!wstring(F.y) == "y"w);
|
enum EF : real { a = 1.414, b = 1.732, c = 2.236 }
|
||||||
assert(to!dstring(F.z) == "z"d);
|
|
||||||
|
foreach (E; TypeTuple!(EU, EI, EF))
|
||||||
|
{
|
||||||
|
assert(to! string(E.a) == "a"c);
|
||||||
|
assert(to!wstring(E.a) == "a"w);
|
||||||
|
assert(to!dstring(E.a) == "a"d);
|
||||||
|
}
|
||||||
|
|
||||||
// Test an value not corresponding to an enum member.
|
// Test an value not corresponding to an enum member.
|
||||||
auto o = cast(E)5;
|
auto o = cast(EU)5;
|
||||||
assert(to! string(o) == "cast(E)5"c);
|
assert(to! string(o) == "cast(EU)5"c);
|
||||||
assert(to!wstring(o) == "cast(E)5"w);
|
assert(to!wstring(o) == "cast(EU)5"w);
|
||||||
assert(to!dstring(o) == "cast(E)5"d);
|
assert(to!dstring(o) == "cast(EU)5"d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
|
|
29
std/traits.d
29
std/traits.d
|
@ -2700,7 +2700,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template BooleanTypeOf(T)
|
template BooleanTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
inout(bool) idx( inout(bool) );
|
inout(bool) idx( inout(bool) );
|
||||||
shared(inout bool) idx( shared(inout bool) );
|
shared(inout bool) idx( shared(inout bool) );
|
||||||
|
@ -2734,7 +2734,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template IntegralTypeOf(T)
|
template IntegralTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
inout( byte) idx( inout( byte) );
|
inout( byte) idx( inout( byte) );
|
||||||
inout( ubyte) idx( inout( ubyte) );
|
inout( ubyte) idx( inout( ubyte) );
|
||||||
|
@ -2793,7 +2793,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template FloatingPointTypeOf(T)
|
template FloatingPointTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
inout( float) idx( inout( float) );
|
inout( float) idx( inout( float) );
|
||||||
inout(double) idx( inout(double) );
|
inout(double) idx( inout(double) );
|
||||||
|
@ -2832,7 +2832,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template NumericTypeOf(T)
|
template NumericTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
static if (is(IntegralTypeOf!T X))
|
static if (is(IntegralTypeOf!T X))
|
||||||
alias X NumericTypeOf;
|
alias X NumericTypeOf;
|
||||||
|
@ -2860,7 +2860,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template UnsignedTypeOf(T)
|
template UnsignedTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
static if (is(IntegralTypeOf!T X) &&
|
static if (is(IntegralTypeOf!T X) &&
|
||||||
staticIndexOf!(Unqual!X, UnsignedIntTypeList) >= 0)
|
staticIndexOf!(Unqual!X, UnsignedIntTypeList) >= 0)
|
||||||
|
@ -2869,7 +2869,7 @@ template UnsignedTypeOf(T)
|
||||||
static assert(0, T.stringof~" is not an unsigned type.");
|
static assert(0, T.stringof~" is not an unsigned type.");
|
||||||
}
|
}
|
||||||
|
|
||||||
template SignedTypeOf(T)
|
template SignedTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
static if (is(IntegralTypeOf!T X) &&
|
static if (is(IntegralTypeOf!T X) &&
|
||||||
staticIndexOf!(Unqual!X, SignedIntTypeList) >= 0)
|
staticIndexOf!(Unqual!X, SignedIntTypeList) >= 0)
|
||||||
|
@ -2882,7 +2882,7 @@ template SignedTypeOf(T)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template CharTypeOf(T)
|
template CharTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
inout( char) idx( inout( char) );
|
inout( char) idx( inout( char) );
|
||||||
inout(wchar) idx( inout(wchar) );
|
inout(wchar) idx( inout(wchar) );
|
||||||
|
@ -2937,7 +2937,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template StaticArrayTypeOf(T)
|
template StaticArrayTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
inout(U[n]) idx(U, size_t n)( inout(U[n]) );
|
inout(U[n]) idx(U, size_t n)( inout(U[n]) );
|
||||||
|
|
||||||
|
@ -2968,7 +2968,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template DynamicArrayTypeOf(T)
|
template DynamicArrayTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
inout(U[]) idx(U)( inout(U[]) );
|
inout(U[]) idx(U)( inout(U[]) );
|
||||||
|
|
||||||
|
@ -3008,7 +3008,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template ArrayTypeOf(T)
|
template ArrayTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
static if (is(StaticArrayTypeOf!T X))
|
static if (is(StaticArrayTypeOf!T X))
|
||||||
alias X ArrayTypeOf;
|
alias X ArrayTypeOf;
|
||||||
|
@ -3024,7 +3024,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template StringTypeOf(T) if (isSomeString!T)
|
template StringTypeOf(T) if (!is(T == enum) && isSomeString!T)
|
||||||
{
|
{
|
||||||
alias ArrayTypeOf!T StringTypeOf;
|
alias ArrayTypeOf!T StringTypeOf;
|
||||||
}
|
}
|
||||||
|
@ -3054,7 +3054,7 @@ unittest
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
template AssocArrayTypeOf(T)
|
template AssocArrayTypeOf(T) if (!is(T == enum))
|
||||||
{
|
{
|
||||||
immutable(V [K]) idx(K, V)( immutable(V [K]) );
|
immutable(V [K]) idx(K, V)( immutable(V [K]) );
|
||||||
|
|
||||||
|
@ -3286,7 +3286,10 @@ Detect whether we can treat T as one of the built-in string types.
|
||||||
*/
|
*/
|
||||||
template isSomeString(T)
|
template isSomeString(T)
|
||||||
{
|
{
|
||||||
enum isSomeString = isNarrowString!T || is(T : const(dchar[]));
|
static if (is(T == enum))
|
||||||
|
enum isSomeString = false;
|
||||||
|
else
|
||||||
|
enum isSomeString = isNarrowString!T || is(T : const(dchar[]));
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue