https://issues.dlang.org/show_bug.cgi?id=23346
Issue ID: 23346
Summary: ImportC: pragma pack is not popped
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC, wrong-code
Severity: normal
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
It seems like #pragma pack(pop) in a C file does not undo a #pragma pack(push).
For example (on a target where sizeof(long) == 8):
#pragma pack(push, 4)
struct Packed {
int x;
long y;
};
#pragma pack(pop)
struct NotPacked {
int x;
// should have 4 bytes of padding
long y;
};
_Static_assert(sizeof(long)==8, "long is not 8 bytes");
_Static_assert(sizeof(struct Packed)==12, "sizeof(Packed) != 12");
_Static_assert(sizeof(struct NotPacked)==16, "sizeof(NotPacked) != 16”); //
This static assertion fails.
Compiling with clang passes the static assertions.
I noticed this when compiling some code on macOS (which unfortunately uses
pragma pack in some system headers).
--