[Issue 20666] New: Variant assignment from const of large type with indirections
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 11 12:04:20 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20666
Issue ID: 20666
Summary: Variant assignment from const of large type with
indirections
Product: D
Version: D2
Hardware: All
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: simen.kjaras at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list