Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compiler/src/dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

@dkorpel dkorpel Jun 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference to keep this a D string and pass it as "%.*s", cast(int) qual.length, qual.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
Expand Down
28 changes: 28 additions & 0 deletions compiler/test/fail_compilation/prefix_qual.d
Original file line number Diff line number Diff line change
@@ -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();
}
Loading