From 5394ae6467ccc8221227d63ad6e4c137ed0fd815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ferreira?= Date: Sun, 3 Oct 2021 20:22:06 +0100 Subject: [PATCH] hdrgen: remove trailing whitespace on attribute declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Issue 22353. Signed-off-by: Luís Ferreira --- src/dmd/hdrgen.d | 10 ++++++++-- test/compilable/extra-files/header1.di | 2 +- test/compilable/extra-files/header1i.di | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/dmd/hdrgen.d b/src/dmd/hdrgen.d index 266da9cfb402..781cf74c6523 100644 --- a/src/dmd/hdrgen.d +++ b/src/dmd/hdrgen.d @@ -909,6 +909,12 @@ public: override void visit(AttribDeclaration d) { + bool hasSTC; + if (auto stcd = d.isStorageClassDeclaration) + { + hasSTC = stcToBuffer(buf, stcd.stc); + } + if (!d.decl) { buf.writeByte(';'); @@ -918,10 +924,12 @@ public: if (d.decl.dim == 0 || (hgs.hdrgen && d.decl.dim == 1 && (*d.decl)[0].isUnitTestDeclaration())) { // hack for bugzilla 8081 + if (hasSTC) buf.writeByte(' '); buf.writestring("{}"); } else if (d.decl.dim == 1) { + if (hasSTC) buf.writeByte(' '); (*d.decl)[0].accept(this); return; } @@ -941,8 +949,6 @@ public: override void visit(StorageClassDeclaration d) { - if (stcToBuffer(buf, d.stc)) - buf.writeByte(' '); visit(cast(AttribDeclaration)d); } diff --git a/test/compilable/extra-files/header1.di b/test/compilable/extra-files/header1.di index 656e246ea004..7203627fd1fb 100644 --- a/test/compilable/extra-files/header1.di +++ b/test/compilable/extra-files/header1.di @@ -511,7 +511,7 @@ ref @safe int foo(return ref int a); ref @safe int* foo(return ref scope int* a); struct SafeS { - @safe + @safe { ref SafeS foo() return; scope SafeS foo2() return; diff --git a/test/compilable/extra-files/header1i.di b/test/compilable/extra-files/header1i.di index 20f9b0297c72..7a2e78abc1e6 100644 --- a/test/compilable/extra-files/header1i.di +++ b/test/compilable/extra-files/header1i.di @@ -647,7 +647,7 @@ ref @safe int* foo(return ref scope int* a) } struct SafeS { - @safe + @safe { ref SafeS foo() return {