Issue 20666 - Variant assignment from const of large type with indirections
Summary: Variant assignment from const of large type with indirections
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Windows
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-11 12:04 UTC by Simen Kjaeraas
Modified: 2024-12-01 16:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Simen Kjaeraas 2020-03-11 12:04:20 UTC
When a type T is small enough, Variant allows assignment from it even if it is not implicitly convertible to Unqual!T. However, when the size of the type is larger than VariantN's size argument, a different path is chosen, and the compiler chokes. This example code showcases the effect - for small i there is no problem, but then there's an compile error when i > 16, 12, or 8 (depending on compiler and flags):

struct S(int padding) {
    byte[padding] _;
    int* p;
}

unittest {
    import std.variant;
    
    static foreach (i; 0..64) {{
        const S!i s;
        Variant a = s;
    }}
}

The code on which the compiler chokes is this:
https://github.com/dlang/phobos/blob/master/std/variant.d#L699-L701

I'm unsure why larger types are treated differently. The comment on lines 667-674 seems to indicate it has to do with whether they're passed on the stack or not, but this assumption does not seem to be documented elsewhere.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:36:31 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10411

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB