Debug help - Programming in D - extending tail slice terminates sharing unexpectedly. Page 69, 70
monkyyy
crazymonkyyy at gmail.com
Mon Oct 20 17:56:24 UTC 2025
On Monday, 20 October 2025 at 14:43:05 UTC, Steven Schveighoffer
wrote:
> On Sunday, 19 October 2025 at 20:44:39 UTC, Brother Bill wrote:
>
>> Console output:
>> ```
>> slice: [1, 3, 5, 7, 9, 11, 13, 15, 17] length: 9 capacity: 11
>>
>> slice: [1, 3, 5, 7, 9, 11, 13, 15, 17] length: 9 capacity: 11
>> tailSlice: [9, 11, 13, 15, 17] length: 5 capacity: 7
>> &tailSlice[0]: 26AAAA31040
>> tailSlice after incrementing length by 1: [9, 11, 13, 15, 17,
>> 0] length: 6 capacity: 11 &tailSlice[0]: 26AAAA31060
>> After tail slice length increase and changing tailSlice[0] to
>> 888. length: 6 capacity: 11
>> tailSlice: [888, 11, 13, 15, 17, 0]
>> slice : [1, 3, 5, 7, 9, 11, 13, 15, 17]
>>
>> ```
>
> This is a bug, introduced in 2.111.0
>
> If you use 2.110.0 you will get the expected behavior.
>
> -Steve
someone swapped the tradeoffs then calling it a bug is misleading
if you disagree pls fix this bug
```d
import std;
bool issubset(T)(T[] a,T[] b){
T* c=min(&a[0],&b[0]);
T* d=max(&a[$-1],&b[$-1]);
return &a[0]==c&& &a[$-1]==d;
}
unittest{
int[100] foo;
assert(issubset(foo[10..20],foo[15..19]));
assert( ! issubset(foo[50..100],foo[15..30]));
}
unittest{
int[] data=[1,2,3];
int[] tail=data[1..$];
assert(issubset(data,tail));
assert(data.capacity>0);
assert(tail.capacity>0);
data.length+=1;
assert(data[$-1]==int.init);
data[$-1]=4;
assert(data[$-1]==4);
assert(issubset(data,tail));
assert(tail.capacity>0);
tail.length+=1;
assert(tail[$-1]==int.init);
assert(issubset(data,tail));
}
```
More information about the Digitalmars-d-learn
mailing list