Skip to content

Commit db204e0

Browse files
authored
Merge pull request #5071 from WalterBright/scope-byUTF
get byUTF() to work with -dip1000
2 parents 5da61ca + 98753ad commit db204e0

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

std/utf.d

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ private dchar decodeImpl(bool canIndex, UseReplacementDchar useReplacementDchar
13021302
alias bitMask = AliasSeq!((1 << 7) - 1, (1 << 11) - 1, (1 << 16) - 1, (1 << 21) - 1);
13031303

13041304
static if (is(S : const char[]))
1305-
auto pstr = str.ptr + index;
1305+
auto pstr = str.ptr + index; // this is what makes decodeImpl() @system code
13061306
else static if (isRandomAccessRange!S && hasSlicing!S && hasLength!S)
13071307
auto pstr = str[index .. str.length];
13081308
else
@@ -3802,17 +3802,12 @@ template byUTF(C) if (isSomeChar!C)
38023802
{
38033803
static struct Result
38043804
{
3805-
this(ref R r)
3806-
{
3807-
this.r = r;
3808-
}
3809-
38103805
@property bool empty()
38113806
{
38123807
return pos == fill && r.empty;
38133808
}
38143809

3815-
@property auto front()
3810+
@property auto front() scope // 'scope' required by call to decodeFront() below
38163811
{
38173812
if (pos == fill)
38183813
{
@@ -3829,14 +3824,12 @@ template byUTF(C) if (isSomeChar!C)
38293824
{
38303825
static if (is(RC == dchar))
38313826
{
3832-
fill = cast(ushort) encode!(Yes.useReplacementDchar)(buf, c);
38333827
r.popFront;
3828+
dchar dc = c;
38343829
}
38353830
else
3836-
{
3837-
fill = cast(ushort) encode!(Yes.useReplacementDchar)(
3838-
buf, decodeFront!(Yes.useReplacementDchar)(r));
3839-
}
3831+
dchar dc = () @trusted { return decodeFront!(Yes.useReplacementDchar)(r); }();
3832+
fill = cast(ushort) encode!(Yes.useReplacementDchar)(buf, dc);
38403833
}
38413834
}
38423835
return buf[pos];

0 commit comments

Comments
 (0)