Fix Issue 4663 - Wrong 'static' position error message (#15321)

Also detects `extern`, `deprecated`, `ref`, `override` and friends.
This commit is contained in:
Nick Treleaven 2023-06-14 06:42:32 +01:00 committed by GitHub
parent 342a226833
commit 7643dc6041
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -1405,6 +1405,15 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
break;
}
default:
Token* tk;
if (skipAttributes(&token, &tk) && tk.ptr != token.ptr ||
token.value == TOK.static_ || token.value == TOK.extern_)
{
error("`%s` token is not allowed in postfix position",
Token.toChars(token.value));
nextToken();
continue;
}
return storageClass;
}
storageClass = appendStorageClass(storageClass, stc);

View file

@ -0,0 +1,21 @@
/*
TEST_OUTPUT:
---
fail_compilation/funcpostattr.d(11): Error: `deprecated` token is not allowed in postfix position
fail_compilation/funcpostattr.d(11): Error: `extern` token is not allowed in postfix position
fail_compilation/funcpostattr.d(15): Error: `static` token is not allowed in postfix position
fail_compilation/funcpostattr.d(15): Error: `ref` token is not allowed in postfix position
fail_compilation/funcpostattr.d(20): Error: `override` token is not allowed in postfix position
---
*/
void foo() deprecated extern;
void main() {
int i;
int foo() static ref => i;
}
class C
{
void foo() override {}
}