diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index b7e07911cb..8c0a1b13c9 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -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); diff --git a/compiler/test/fail_compilation/funcpostattr.d b/compiler/test/fail_compilation/funcpostattr.d new file mode 100644 index 0000000000..b50db058e3 --- /dev/null +++ b/compiler/test/fail_compilation/funcpostattr.d @@ -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 {} +}