diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-03-21 16:52:40 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-03-21 19:51:50 +0100 |
commit | fbdaa58162ee4189f441b75170af89215465d189 (patch) | |
tree | 77c5816b721cad2691bea1d228cb5ecc31568f9c /libphobos | |
parent | 4a3073f04e8b7987ad7bfe1bc23bfeb1d627ee6a (diff) | |
download | gcc-fbdaa58162ee4189f441b75170af89215465d189.zip gcc-fbdaa58162ee4189f441b75170af89215465d189.tar.gz gcc-fbdaa58162ee4189f441b75170af89215465d189.tar.bz2 |
d: Merge upstream dmd 2503f17e5, phobos a74fa63e6.
D front-end changes:
- Import dmd mainline development.
- Removed internal d_intN and d_unsN aliases to stdint types, which
caused a regression on Solaris where int8_t is a char (PR104911).
Phobos changes:
- Import phobos mainline development.
PR d/104911
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd 2503f17e5.
* d-convert.cc (convert_expr): Replace d_uns64 with dinteger_t.
* d-lang.cc: Remove dmd/root/file.h include.
(d_handle_option): Update for new front-end interface.
(d_parse_file): Likewise.
libphobos/ChangeLog:
* src/MERGE: Merge upstream phobos a74fa63e6.
Diffstat (limited to 'libphobos')
-rw-r--r-- | libphobos/src/MERGE | 2 | ||||
-rw-r--r-- | libphobos/src/std/conv.d | 35 | ||||
-rw-r--r-- | libphobos/src/std/sumtype.d | 35 | ||||
-rw-r--r-- | libphobos/src/std/traits.d | 40 | ||||
-rw-r--r-- | libphobos/src/std/uni/package.d | 4 |
5 files changed, 97 insertions, 19 deletions
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index 963ffe0..6eb555e 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -16cb085b584f100fa677e2e64ff6b6dbb4921ad1 +a74fa63e6775d626850d8ebd854d9803c7ffb97d The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d index 8512a44..06b3797 100644 --- a/libphobos/src/std/conv.d +++ b/libphobos/src/std/conv.d @@ -1153,7 +1153,7 @@ if (!(isImplicitlyConvertible!(S, T) && } // https://issues.dlang.org/show_bug.cgi?id=16108 -@system unittest +@safe unittest { static struct A { @@ -1341,12 +1341,12 @@ if (is (T == immutable) && isExactSomeString!T && is(S == enum)) assert(to!string(a) == "[1.5, 2.5]"); } -@system unittest +@safe unittest { // Conversion representing class object with string class A { - override string toString() const { return "an A"; } + override string toString() @safe const { return "an A"; } } A a; assert(to!string(a) == "null"); @@ -1354,7 +1354,7 @@ if (is (T == immutable) && isExactSomeString!T && is(S == enum)) assert(to!string(a) == "an A"); // https://issues.dlang.org/show_bug.cgi?id=7660 - class C { override string toString() const { return "C"; } } + class C { override string toString() @safe const { return "C"; } } struct S { C c; alias c this; } S s; s.c = new C(); assert(to!string(s) == "C"); @@ -1739,10 +1739,10 @@ if (!isImplicitlyConvertible!(S, T) && isAssociativeArray!S && foreach (k1, v1; value) { // Cast values temporarily to Unqual!V2 to store them to result variable - result[to!K2(k1)] = cast(Unqual!V2) to!V2(v1); + result[to!K2(k1)] = to!(Unqual!V2)(v1); } // Cast back to original type - return cast(T) result; + return () @trusted { return cast(T) result; }(); } @safe unittest @@ -3105,7 +3105,7 @@ if (isSomeString!Source && !is(Source == enum) && * A $(LREF ConvException) if `source` is empty, if no number could be * parsed, or if an overflow occurred. */ -auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source) +auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref scope Source source) if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum) && isFloatingPoint!Target && !is(Target == enum)) { @@ -3122,6 +3122,13 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum alias p = source; } + void advanceSource() @trusted + { + // p is assigned from source.representation above so the cast is valid + static if (isNarrowString!Source) + source = cast(Source) p; + } + static immutable real[14] negtab = [ 1e-4096L,1e-2048L,1e-1024L,1e-512L,1e-256L,1e-128L,1e-64L,1e-32L, 1e-16L,1e-8L,1e-4L,1e-2L,1e-1L,1.0L ]; @@ -3138,6 +3145,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum enforce(!p.empty, bailOut()); + size_t count = 0; bool sign = false; switch (p.front) @@ -3168,8 +3176,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum // skip past the last 'f' ++count; p.popFront(); - static if (isNarrowString!Source) - source = cast(Source) p; + advanceSource(); static if (doCount) { return tuple!("data", "count")(sign ? -Target.infinity : Target.infinity, count); @@ -3189,8 +3196,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum p.popFront(); if (p.empty) { - static if (isNarrowString!Source) - source = cast(Source) p; + advanceSource(); static if (doCount) { return tuple!("data", "count")(cast (Target) (sign ? -0.0 : 0.0), count); @@ -3222,8 +3228,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum // skip past the last 'n' ++count; p.popFront(); - static if (isNarrowString!Source) - source = cast(Source) p; + advanceSource(); static if (doCount) { return tuple!("data", "count")(Target.nan, count); @@ -3418,8 +3423,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum // if overflow occurred enforce(ldval != real.infinity, new ConvException("Range error")); - static if (isNarrowString!Source) - source = cast(Source) p; + advanceSource(); static if (doCount) { return tuple!("data", "count")(cast (Target) (sign ? -ldval : ldval), count); @@ -3430,6 +3434,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum } } + /// @safe unittest { diff --git a/libphobos/src/std/sumtype.d b/libphobos/src/std/sumtype.d index 8da38bd..f4f4216 100644 --- a/libphobos/src/std/sumtype.d +++ b/libphobos/src/std/sumtype.d @@ -234,7 +234,7 @@ import std.meta : anySatisfy, allSatisfy; import std.traits : hasElaborateCopyConstructor, hasElaborateDestructor; import std.traits : isAssignable, isCopyable, isStaticArray, isRvalueAssignable; import std.traits : ConstOf, ImmutableOf, InoutOf, TemplateArgsOf; -import std.traits : CommonType; +import std.traits : CommonType, DeducedParameterType; import std.typecons : ReplaceTypeUnless; import std.typecons : Flag; @@ -359,6 +359,10 @@ public: /// ditto this(immutable(T) value) immutable; + + /// ditto + this(Value)(Value value) inout + if (is(Value == DeducedParameterType!(inout(T)))); } static foreach (tid, T; Types) @@ -414,6 +418,25 @@ public: { @disable this(immutable(T) value) immutable; } + + static if (isCopyable!(inout(T))) + { + static if (IndexOf!(inout(T), Map!(InoutOf, Types)) == tid) + { + /// ditto + this(Value)(Value value) inout + if (is(Value == DeducedParameterType!(inout(T)))) + { + __traits(getMember, storage, Storage.memberName!T) = value; + tag = tid; + } + } + } + else + { + @disable this(Value)(Value value) inout + if (is(Value == DeducedParameterType!(inout(T)))); + } } static if (anySatisfy!(hasElaborateCopyConstructor, Types)) @@ -1554,6 +1577,16 @@ version (D_BetterC) {} else SumType!Value s; } +// Construction of inout-qualified SumTypes +// https://issues.dlang.org/show_bug.cgi?id=22901 +@safe unittest +{ + static inout(SumType!(int[])) example(inout(int[]) arr) + { + return inout(SumType!(int[]))(arr); + } +} + /// True if `T` is an instance of the `SumType` template, otherwise false. private enum bool isSumTypeInstance(T) = is(T == SumType!Args, Args...); diff --git a/libphobos/src/std/traits.d b/libphobos/src/std/traits.d index 596c11c..9ca676d 100644 --- a/libphobos/src/std/traits.d +++ b/libphobos/src/std/traits.d @@ -9080,3 +9080,43 @@ enum isCopyable(S) = __traits(isCopyable, S); static assert(isCopyable!int); static assert(isCopyable!(int[])); } + +/** + * The parameter type deduced by IFTI when an expression of type T is passed as + * an argument to a template function. + * + * For all types other than pointer and slice types, `DeducedParameterType!T` + * is the same as `T`. For pointer and slice types, it is `T` with the + * outer-most layer of qualifiers dropped. + */ +package(std) template DeducedParameterType(T) +{ + static if (is(T == U*, U) || is(T == U[], U)) + alias DeducedParameterType = Unqual!T; + else + alias DeducedParameterType = T; +} + +@safe unittest +{ + static assert(is(DeducedParameterType!(const(int)) == const(int))); + static assert(is(DeducedParameterType!(const(int[2])) == const(int[2]))); + + static assert(is(DeducedParameterType!(const(int*)) == const(int)*)); + static assert(is(DeducedParameterType!(const(int[])) == const(int)[])); +} + +@safe unittest +{ + static struct NoCopy + { + @disable this(this); + } + + static assert(is(DeducedParameterType!NoCopy == NoCopy)); +} + +@safe unittest +{ + static assert(is(DeducedParameterType!(inout(int[])) == inout(int)[])); +} diff --git a/libphobos/src/std/uni/package.d b/libphobos/src/std/uni/package.d index 9780b1b..eeeda72 100644 --- a/libphobos/src/std/uni/package.d +++ b/libphobos/src/std/uni/package.d @@ -9824,7 +9824,7 @@ dchar toLower(dchar c) /++ Creates a new array which is identical to `s` except that all of its - characters are converted to lowercase (by preforming Unicode lowercase mapping). + characters are converted to lowercase (by performing Unicode lowercase mapping). If none of `s` characters were affected, then `s` itself is returned if `s` is a `string`-like type. @@ -10028,7 +10028,7 @@ dchar toUpper(dchar c) /++ Allocates a new array which is identical to `s` except that all of its - characters are converted to uppercase (by preforming Unicode uppercase mapping). + characters are converted to uppercase (by performing Unicode uppercase mapping). If none of `s` characters were affected, then `s` itself is returned if `s` is a `string`-like type. |