ImportC: allow _Alignof expression (#21181)

Resolves https://github.com/dlang/dmd/issues/20434

Allowing this gnu/clang extension actually removes lines of code as
we can unify the parsing and semantics of `_Alignof` and `sizeof`
and have the normal D machinery handle the difference later.
This commit is contained in:
drpriver 2025-04-09 16:20:50 -07:00 committed by GitHub
parent 93b0317cc3
commit a0bf0f368a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 9 additions and 71 deletions

View file

@ -3,10 +3,10 @@
int printf(const char *, ...);
_Alignas(4) _Alignas(8) _Alignas(0) int x = 5;
//_Static_assert(_Alignof(x) == 8, "in");
_Static_assert(_Alignof(x) == 8, "in");
_Alignas(int) short y = 6;
//_Static_assert(_Alignof(y) == 4, "in");
_Static_assert(_Alignof(y) == 4, "in");
struct S
{

View file

@ -329,6 +329,7 @@ void test4(int i)
_Static_assert(sizeof 3 == 4, "ok");
_Static_assert(sizeof(3) == 4, "ok");
_Static_assert(_Alignof(int) == 4, "ok");
_Static_assert(_Alignof 3 == 4, "ok");
_Static_assert((int)3 == 3, "ok");
_Static_assert(sizeof p[0] == 4, "ok");
_Static_assert(1 && 2, "ok");

View file

@ -1,17 +0,0 @@
/* TEST_OUTPUT:
---
fail_compilation/test22246.c(106): Error: argument to `_Alignof` must be a type
---
*/
// https://issues.dlang.org/show_bug.cgi?id=22246
#line 100
struct S { int m; };
int test()
{
struct S s;
return _Alignof(s);
}