Fix #21271 - ImportC: incorrect compatibility macro for __pragma

Fixes https://github.com/dlang/dmd/issues/21271

Redefine the compatibility macro in terms of C99's `_Pragma()`
instead of ignoring it. Clang and GCC will replace `_Pragma()`
with `#pragma` directives in the preprocessed output, while
cl.exe will actually convert it back to `__pragma()`.

This is still a better situation than before as ImportC partially
supports `__pragma()`.
This commit is contained in:
drpriver 2025-04-18 22:02:47 -07:00 committed by Nicholas Wilson
parent dfe501dde6
commit 856d4921a0
2 changed files with 17 additions and 1 deletions

View file

@ -0,0 +1,16 @@
// https://github.com/dlang/dmd/issues/21271
#define PUSH __pragma(pack(push))
#define PACK __pragma(pack(1))
#define POP __pragma(pack(pop))
PUSH
PACK
struct S21271_1 {
int x;
};
_Static_assert(_Alignof(struct S21271_1)==1, "1");
POP
struct S21271_2 {
int x;
};
_Static_assert(_Alignof(struct S21271_2)==_Alignof(int), "2");

View file

@ -59,7 +59,7 @@
#define __forceinline __attribute__((always_inline))
#undef _Check_return_
//#define _Check_return_
#define __pragma(x)
#define __pragma(x) _Pragma(#x)
#undef _GLIBCXX_USE_FLOAT128