Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment not applied when type is inferred #20727

Open
Bolpat opened this issue Jan 18, 2025 · 0 comments
Open

Alignment not applied when type is inferred #20727

Bolpat opened this issue Jan 18, 2025 · 0 comments

Comments

@Bolpat
Copy link
Contributor

Bolpat commented Jan 18, 2025

When align is the last attribute/storage class of a local variable whose type is inferred, it is silently ignored.

The alignment attribute is correctly applied when a type is stated or a storage class is between the alignment attribute and the variable name.

void f()
{
    static align(8) x = 10;
    static align(8) int y = 10;
    static assert(is(typeof(x) == typeof(y))); // passes
    static assert(x.alignof == y.alignof); // fails: `4LU == 8LU` is false
}

void g()
{
    align(8) static x = 10;
    align(8) static int y = 10;
    static assert(is(typeof(x) == typeof(y))); // passes
    static assert(x.alignof == y.alignof); // passes
}

It also only affects local variables; member and global-scope variables are handled differently:

struct S
{
    static align(8) x = 10; // parse error: basic type expected
}

struct T
{
    align(8) static x = 10;
    align(8) static int y = 10;
    static assert(is(typeof(x) == typeof(y))); // passes
    static assert(x.alignof == y.alignof); // passes
}
static align(8) x = 10; // parse error: basic type expected
align(8) static x = 10;
align(8) static int y = 10;
static assert(is(typeof(x) == typeof(y))); // passes
static assert(x.alignof == y.alignof); // passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant