mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
parent
b88ffc50d7
commit
3f90de47c1
4 changed files with 58 additions and 4 deletions
23
changelog/dmd.default-align.dd
Normal file
23
changelog/dmd.default-align.dd
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
The `align` attribute now allows to specify `default` explicitly
|
||||||
|
|
||||||
|
A lone `align` sets the alignment to the type’s default.
|
||||||
|
Alternatively, to be more explicit, `align(default)` does the same.
|
||||||
|
|
||||||
|
```
|
||||||
|
struct S
|
||||||
|
{
|
||||||
|
align(4)
|
||||||
|
{
|
||||||
|
byte x;
|
||||||
|
align(default) long y;
|
||||||
|
long z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
pragma(msg, S.x.alignof); // 4
|
||||||
|
pragma(msg, S.y.alignof); // 8
|
||||||
|
pragma(msg, S.z.alignof); // 4
|
||||||
|
}
|
||||||
|
```
|
|
@ -939,7 +939,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
|
||||||
if (e)
|
if (e)
|
||||||
error("redundant alignment attribute `align(%s)`", e.toChars());
|
error("redundant alignment attribute `align(%s)`", e.toChars());
|
||||||
else
|
else
|
||||||
error("redundant alignment attribute `align`");
|
error("redundant alignment attribute `align(default)`");
|
||||||
}
|
}
|
||||||
|
|
||||||
pAttrs.setAlignment = true;
|
pAttrs.setAlignment = true;
|
||||||
|
@ -4387,7 +4387,10 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
|
||||||
if (token.value == TOK.leftParenthesis)
|
if (token.value == TOK.leftParenthesis)
|
||||||
{
|
{
|
||||||
nextToken();
|
nextToken();
|
||||||
e = parseAssignExp();
|
if (token.value == TOK.default_)
|
||||||
|
nextToken();
|
||||||
|
else
|
||||||
|
e = parseAssignExp();
|
||||||
check(TOK.rightParenthesis);
|
check(TOK.rightParenthesis);
|
||||||
}
|
}
|
||||||
return e;
|
return e;
|
||||||
|
|
28
compiler/test/compilable/aligndefault.d
Normal file
28
compiler/test/compilable/aligndefault.d
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
struct S
|
||||||
|
{
|
||||||
|
align(1)
|
||||||
|
{
|
||||||
|
short x1;
|
||||||
|
int y1;
|
||||||
|
long z1;
|
||||||
|
|
||||||
|
align(default)
|
||||||
|
{
|
||||||
|
short x;
|
||||||
|
int y;
|
||||||
|
long z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fun()
|
||||||
|
{
|
||||||
|
static assert(S.x1.alignof == 1);
|
||||||
|
static assert(S.y1.alignof == 1);
|
||||||
|
static assert(S.z1.alignof == 1);
|
||||||
|
|
||||||
|
static assert(S.x.alignof == short.alignof);
|
||||||
|
static assert(S.y.alignof == int.alignof);
|
||||||
|
static assert(S.z.alignof == long.alignof);
|
||||||
|
}
|
|
@ -53,10 +53,10 @@ public private void f10() {}
|
||||||
/*
|
/*
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/parseStc2.d(63): Error: redundant alignment attribute `align`
|
fail_compilation/parseStc2.d(63): Error: redundant alignment attribute `align(default)`
|
||||||
fail_compilation/parseStc2.d(64): Error: redundant alignment attribute `align(1)`
|
fail_compilation/parseStc2.d(64): Error: redundant alignment attribute `align(1)`
|
||||||
fail_compilation/parseStc2.d(65): Error: redundant alignment attribute `align(1)`
|
fail_compilation/parseStc2.d(65): Error: redundant alignment attribute `align(1)`
|
||||||
fail_compilation/parseStc2.d(66): Error: redundant alignment attribute `align`
|
fail_compilation/parseStc2.d(66): Error: redundant alignment attribute `align(default)`
|
||||||
fail_compilation/parseStc2.d(67): Error: redundant alignment attribute `align(2)`
|
fail_compilation/parseStc2.d(67): Error: redundant alignment attribute `align(2)`
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue