From 006ee446f886c5a0f8147908501d287236dd6197 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 12 Nov 2016 12:17:27 +0000 Subject: [PATCH 1/4] Fix Issue 16478 - Don't allow to!T() in constraint Also avoid highlighting 'to' unnecessarily. --- std/conv.d | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/std/conv.d b/std/conv.d index 0b1a7c995d2..ce1f67abe9d 100644 --- a/std/conv.d +++ b/std/conv.d @@ -122,10 +122,9 @@ private (is(Unqual!S == typeof(null))) && isExactSomeString!T; } - template isRawStaticArray(T, A...) + template isRawStaticArray(T) { enum isRawStaticArray = - A.length == 0 && isStaticArray!T && !is(T == class) && !is(T == interface) && @@ -177,13 +176,15 @@ $(I UnsignedInteger): */ template to(T) { + /// T to(A...)(A args) - if (!isRawStaticArray!A) + if (A.length && !isRawStaticArray!(A[0])) { return toImpl!T(args); } // Fix issue 6175 + /// T to(S)(ref S arg) if (isRawStaticArray!S) { @@ -230,7 +231,7 @@ template to(T) * When converting strings _to numeric types, note that the D hexadecimal and binary * literals are not handled. Neither the prefixes that indicate the base, nor the * horizontal bar used _to separate groups of digits are recognized. This also - * applies to the suffixes that indicate the type. + * applies _to the suffixes that indicate the type. * * _To work around this, you can specify a radix for conversions involving numbers. */ @@ -333,12 +334,12 @@ template to(T) * $(LI Unsigned or signed integers _to strings. * $(DL $(DT [special case]) * $(DD Convert integral value _to string in $(D_PARAM radix) radix. - * radix must be a value from 2 to 36. + * radix must be a value from 2 _to 36. * value is treated as a signed value only if radix is 10. - * The characters A through Z are used to represent values 10 through 36 + * The characters A through Z are used _to represent values 10 through 36 * and their case is determined by the $(D_PARAM letterCase) parameter.))) * $(LI All floating point types _to all string types.) - * $(LI Pointer to string conversions prints the pointer as a $(D size_t) value. + * $(LI Pointer _to string conversions prints the pointer as a $(D size_t) value. * If pointer is $(D char*), treat it as C-style strings. * In that case, this function is $(D @system).)) */ From b967d944a2e8d0639e8ab881e71bc5121804fc22 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 12 Nov 2016 12:22:20 +0000 Subject: [PATCH 2/4] Remove isRawStaticArray - same as isStaticArray isStaticArray!T already checks !isAggregateType!T. --- std/conv.d | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/std/conv.d b/std/conv.d index ce1f67abe9d..e70970d338f 100644 --- a/std/conv.d +++ b/std/conv.d @@ -121,16 +121,6 @@ private enum isNullToStr = isImplicitlyConvertible!(S, T) && (is(Unqual!S == typeof(null))) && isExactSomeString!T; } - - template isRawStaticArray(T) - { - enum isRawStaticArray = - isStaticArray!T && - !is(T == class) && - !is(T == interface) && - !is(T == struct) && - !is(T == union); - } } /** @@ -178,7 +168,7 @@ template to(T) { /// T to(A...)(A args) - if (A.length && !isRawStaticArray!(A[0])) + if (A.length > 0 && !isStaticArray!(A[0])) { return toImpl!T(args); } @@ -186,7 +176,7 @@ template to(T) // Fix issue 6175 /// T to(S)(ref S arg) - if (isRawStaticArray!S) + if (isStaticArray!S) { return toImpl!T(arg); } @@ -537,7 +527,7 @@ private T toImpl(T, S)(S value) Converting static arrays forwards to their dynamic counterparts. */ private T toImpl(T, S)(ref S s) - if (isRawStaticArray!S) + if (isStaticArray!S) { return toImpl!(T, typeof(s[0])[])(s); } From 43f37800ab1cb27706db322c3b5e497b31184a7d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 14 Nov 2016 10:51:08 +0000 Subject: [PATCH 3/4] Defer doc changes to another PR --- std/conv.d | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/std/conv.d b/std/conv.d index e70970d338f..f5b4386f877 100644 --- a/std/conv.d +++ b/std/conv.d @@ -166,7 +166,6 @@ $(I UnsignedInteger): */ template to(T) { - /// T to(A...)(A args) if (A.length > 0 && !isStaticArray!(A[0])) { @@ -174,7 +173,6 @@ template to(T) } // Fix issue 6175 - /// T to(S)(ref S arg) if (isStaticArray!S) { @@ -221,7 +219,7 @@ template to(T) * When converting strings _to numeric types, note that the D hexadecimal and binary * literals are not handled. Neither the prefixes that indicate the base, nor the * horizontal bar used _to separate groups of digits are recognized. This also - * applies _to the suffixes that indicate the type. + * applies to the suffixes that indicate the type. * * _To work around this, you can specify a radix for conversions involving numbers. */ @@ -324,12 +322,12 @@ template to(T) * $(LI Unsigned or signed integers _to strings. * $(DL $(DT [special case]) * $(DD Convert integral value _to string in $(D_PARAM radix) radix. - * radix must be a value from 2 _to 36. + * radix must be a value from 2 to 36. * value is treated as a signed value only if radix is 10. - * The characters A through Z are used _to represent values 10 through 36 + * The characters A through Z are used to represent values 10 through 36 * and their case is determined by the $(D_PARAM letterCase) parameter.))) * $(LI All floating point types _to all string types.) - * $(LI Pointer _to string conversions prints the pointer as a $(D size_t) value. + * $(LI Pointer to string conversions prints the pointer as a $(D size_t) value. * If pointer is $(D char*), treat it as C-style strings. * In that case, this function is $(D @system).)) */ From b612dcdd56772962635548328f9046e2e46c8f6c Mon Sep 17 00:00:00 2001 From: Steven Schveighoffer Date: Wed, 23 Nov 2016 17:23:24 -0500 Subject: [PATCH 4/4] Fix constraint --- std/conv.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/conv.d b/std/conv.d index f5b4386f877..12e66adbaf9 100644 --- a/std/conv.d +++ b/std/conv.d @@ -167,7 +167,7 @@ $(I UnsignedInteger): template to(T) { T to(A...)(A args) - if (A.length > 0 && !isStaticArray!(A[0])) + if (A.length != 1 || !isStaticArray!(A[0])) { return toImpl!T(args); }