Issue 6742 - Alignments in std.variant.Algebraic
Summary: Alignments in std.variant.Algebraic
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords: bootcamp
Depends on:
Blocks:
 
Reported: 2011-09-29 11:07 UTC by bearophile_hugs
Modified: 2024-12-01 16:14 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-09-29 11:07:53 UTC
In DMD 2.056head std.variant.Algebraic seems to ignore alignment requirements:


import std.variant: Algebraic;
static assert(double.alignof == 8);
struct Foo { double x; }
alias Algebraic!(Foo) AFoo1;
static assert(AFoo1.sizeof == 12);
struct AFoo2 {
    bool b;
    double x;
}
static assert(AFoo2.sizeof == 16);
void main() {}
Comment 1 SomeDude 2012-04-27 15:05:18 UTC
Compiles and runs on 2.059 Win32
Comment 2 bearophile_hugs 2012-05-22 15:22:50 UTC
(In reply to comment #1)
> Compiles and runs on 2.059 Win32

That's the problem. I think AFoo1.sizeof has to be 16 byte, to respect the algnment of doubles that is 8.
Comment 3 AndyC 2015-01-30 02:40:46 UTC
In DMD 2.066.1, I get:


import std.variant: Algebraic;
static assert(double.alignof == 8); //  Error here, this should be 4.

struct Foo { double x; }
alias Algebraic!(Foo) AFoo1;
static assert(AFoo1.sizeof == 12);
struct AFoo2 {
    bool b;
    double x;
}
static assert(AFoo2.sizeof == 16);  // Error here, it should be 12.
void main() {}

I'm not sure what that means though.
Comment 4 berni44 2019-12-03 10:14:21 UTC
On linux, the current compile reports 8 / 16 / 16. As far as I understand this, this is correct. Did not test windows though.
Comment 5 dlangBugzillaToGithub 2024-12-01 16:14:29 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

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

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