Fix #9585 Add check variant alignment (#10690)

* Fix #9585 Add check `variant` alignment

There has been code that handles alignment for a long time
now, and while this module is unlikely to be touched anymore, create a
regression test so the issue can be closed.

* Apparently double is 32bit aligned on x86
This commit is contained in:
Inkrementator 2025-03-19 05:20:30 +01:00 committed by GitHub
parent c79914db2d
commit 67afde4f10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3255,3 +3255,16 @@ if (isAlgebraic!VariantType && Handler.length > 0)
immutable aa = ["0": 0];
auto v = Variant(aa); // compile error
}
// https://issues.dlang.org/show_bug.cgi?id=8195
// Verify that alignment is respected
@safe unittest
{
static struct Foo { double x; }
alias AFoo1 = Algebraic!(Foo);
static assert(AFoo1.alignof >= double.alignof);
// Algebraic using a function pointer is an implementation detail. If test fails, this is safe to change
enum FP_SIZE = (int function()).sizeof;
static assert(AFoo1.sizeof >= double.sizeof + FP_SIZE);
}