Debugging silent exit of threads in Phobos calls

Steven Schveighoffer schveiguy at yahoo.com
Fri Jun 1 20:19:25 UTC 2018


On 6/1/18 1:41 PM, Russel Winder wrote:
> struct Datum {
> 	public const int a;
> 	public const int b;
> }
> 
> struct Message {
> 	Datum datum;
> }

I found the bug. Basically, the Variant static if is failing because the 
assignment it is checking (assigning a Message to a Message) would 
overwrite const data. But it's not really overwriting existing data, 
it's emplacing into new data (always). So this check is not correct.

Much simpler test case:

struct S
{
    const int x;
}

void main()
{
    import std.variant;
    import std.stdio;
    Variant v = S(1);
    writeln(v.get!S); // same failure
}


If I replace the check in std.variant:

                 static if (is(typeof(*cast(T*) target = *src)) ||

with:

                 static if (is(typeof(delegate T() {return *src;})) ||

Then it works (both your code, and the simple example).

Note that in all cases, variant is returning a COPY of the data, not a 
reference, so it shouldn't be possible to violate const.

Please, file a bug. I will see if I can submit a PR to fix.

-Steve


More information about the Digitalmars-d-learn mailing list