diff --git a/changelog/dmd.postfix-this-attributes.dd b/changelog/dmd.postfix-this-attributes.dd new file mode 100644 index 0000000000..1a299d1aea --- /dev/null +++ b/changelog/dmd.postfix-this-attributes.dd @@ -0,0 +1,13 @@ +Postfix type qualifier method attributes for `-H` and `-D` + +`.di` interface file generation and Ddoc output will now have type qualifier +attributes placed after the parameter list for methods (and constructors). +This avoids confusion with the return type. + +--- +struct S +{ + const int f(); // before + int f() const; // now +} +--- diff --git a/compiler/src/dmd/hdrgen.d b/compiler/src/dmd/hdrgen.d index dfb90d6c6a..d4c99255fd 100644 --- a/compiler/src/dmd/hdrgen.d +++ b/compiler/src/dmd/hdrgen.d @@ -3927,7 +3927,7 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te /* Use 'storage class' (prefix) style for attributes */ - if (t.mod && !hgs.ddoc) + if (t.mod && !(hgs.ddoc || hgs.hdrgen)) { MODtoBuffer(buf, t.mod); buf.writeByte(' '); @@ -3977,8 +3977,8 @@ private void visitFuncIdentWithPrefix(TypeFunction t, const Identifier ident, Te buf.writeByte(')'); } parametersToBuffer(t.parameterList, buf, hgs); - // postfix TypeCtor attributes are more readable - if (t.mod && hgs.ddoc) + // postfix this attributes are more readable + if (t.mod && (hgs.ddoc || hgs.hdrgen)) { buf.writeByte(' '); MODtoBuffer(buf, t.mod); diff --git a/compiler/test/compilable/extra-files/header1.di b/compiler/test/compilable/extra-files/header1.di index 91422fed8a..a894d0847b 100644 --- a/compiler/test/compilable/extra-files/header1.di +++ b/compiler/test/compilable/extra-files/header1.di @@ -359,8 +359,8 @@ int bar11(T)() } struct S6360 { - const pure nothrow @property long weeks1(); - const pure nothrow @property long weeks2(); + pure nothrow @property long weeks1() const; + pure nothrow @property long weeks2() const; } struct S12 { @@ -369,10 +369,10 @@ struct S12 } struct T12 { - immutable this()(int args) + this()(int args) immutable { } - immutable this(A...)(A args) + this(A...)(A args) immutable { } } @@ -502,7 +502,7 @@ size_t magic(); class Foo2A { immutable(FooA) Dummy = new immutable(FooA); - private immutable pure nothrow @nogc @safe this(); + private pure nothrow @nogc @safe this() immutable; } struct Foo3A(T) { @@ -560,4 +560,4 @@ interface I12344 assert(result > 0); } ; -} +} \ No newline at end of file diff --git a/compiler/test/compilable/extra-files/header1i.di b/compiler/test/compilable/extra-files/header1i.di index a77f3cb094..754c7ac80b 100644 --- a/compiler/test/compilable/extra-files/header1i.di +++ b/compiler/test/compilable/extra-files/header1i.di @@ -452,11 +452,11 @@ int bar11(T)() } struct S6360 { - const pure nothrow @property long weeks1() + pure nothrow @property long weeks1() const { return 0; } - const pure nothrow @property long weeks2() + pure nothrow @property long weeks2() const { return 0; } @@ -472,10 +472,10 @@ struct S12 } struct T12 { - immutable this()(int args) + this()(int args) immutable { } - immutable this(A...)(A args) + this(A...)(A args) immutable { } } @@ -624,7 +624,7 @@ size_t magic() class Foo2A { immutable(FooA) Dummy = new immutable(FooA); - private immutable pure nothrow @nogc @safe this() + private pure nothrow @nogc @safe this() immutable { } } @@ -715,4 +715,4 @@ interface I12344 assert(result > 0); } ; -} +} \ No newline at end of file diff --git a/compiler/test/compilable/header18365.d b/compiler/test/compilable/header18365.d index 7e51fb26cc..8846c86c44 100644 --- a/compiler/test/compilable/header18365.d +++ b/compiler/test/compilable/header18365.d @@ -13,7 +13,7 @@ struct FullCaseEntry ubyte n; ubyte size; ubyte entry_len; - auto const pure nothrow @nogc @property @trusted value() return + auto pure nothrow @nogc @property @trusted value() const return { return seq[0..entry_len]; }