Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variant assignment from const of large type with indirections #10411

Open
dlangBugzillaToGithub opened this issue Mar 11, 2020 · 0 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

dlangBugzillaToGithub commented Mar 11, 2020

simen.kjaras reported this on 2020-03-11T12:04:20Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20666

Description

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.
@thewilsonator thewilsonator removed P3 OS:Windows Issues Specific to Windows labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants