diff --git a/compiler/src/dmd/parse.d b/compiler/src/dmd/parse.d index ef93b59e3414..f9e7b63df5c5 100644 --- a/compiler/src/dmd/parse.d +++ b/compiler/src/dmd/parse.d @@ -4287,6 +4287,19 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer } } + if (mod.edition >= Edition.v2024 && storageClass & STC.TYPECTOR) + { + typeof(AST.Declaration.storage_class) stc = storageClass & STC.TYPECTOR; + auto qual = (AST.stcToString(stc) ~ '\0').ptr; + deprecation(token.loc, "function declaration `%s` has `%s` type qualifier in prefix position", + pident.toChars(), qual); + if (t) + deprecationSupplemental("either use return type `%s(%s)` instead or move qualifier after parameter list", + qual, t.toChars()); + else + deprecationSupplemental("add `auto` if necessary and move `%s` after parameter list", + qual); + } auto parameterList = parseParameterList(null); /* Parse const/immutable/shared/inout/nothrow/pure/return postfix diff --git a/compiler/test/fail_compilation/prefix_qual.d b/compiler/test/fail_compilation/prefix_qual.d new file mode 100644 index 000000000000..e39a62cb5da9 --- /dev/null +++ b/compiler/test/fail_compilation/prefix_qual.d @@ -0,0 +1,28 @@ +/* +REQUIRED_ARGS: -de +TEST_OUTPUT: +--- +fail_compilation/prefix_qual.d(17): Deprecation: function declaration `f` has `const` type qualifier in prefix position +fail_compilation/prefix_qual.d(17): either use return type `const(int)` instead or move qualifier after parameter list +fail_compilation/prefix_qual.d(18): Deprecation: function declaration `bar` has `const` type qualifier in prefix position +fail_compilation/prefix_qual.d(18): either use return type `const(Foo*)` instead or move qualifier after parameter list +fail_compilation/prefix_qual.d(20): Deprecation: function declaration `g` has `inout` type qualifier in prefix position +fail_compilation/prefix_qual.d(20): add `auto` if necessary and move `inout` after parameter list +--- +*/ + +module m 2024; + +struct Foo { + ref const int f(); + shared const Foo* bar(); + // inferred return type + inout g() => 2; + +// OK +const { + void h(); +} +const: + void i(); +}