Skip to content

Commit

Permalink
hdrgen: remove trailing whitespace on attribute declarations
Browse files Browse the repository at this point in the history
Fixes Issue 22353.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
  • Loading branch information
ljmf00 committed Oct 3, 2021
1 parent 2defede commit 5995579
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/dmd/hdrgen.d
Expand Up @@ -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(';');
Expand All @@ -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;
}
Expand All @@ -941,8 +949,6 @@ public:

override void visit(StorageClassDeclaration d)
{
if (stcToBuffer(buf, d.stc))
buf.writeByte(' ');
visit(cast(AttribDeclaration)d);
}

Expand Down
2 changes: 1 addition & 1 deletion test/compilable/extra-files/header1.di
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/compilable/extra-files/header1i.di
Expand Up @@ -647,7 +647,7 @@ ref @safe int* foo(return ref scope int* a)
}
struct SafeS
{
@safe
@safe
{
ref SafeS foo() return
{
Expand Down
76 changes: 76 additions & 0 deletions test/compilable/hdrgen_dip1029.d
@@ -0,0 +1,76 @@
/*
REQUIRED_ARGS: -o- -Hf${RESULTS_DIR}/compilable/hdrgen_dip1029.di
PERMUTE_ARGS:
OUTPUT_FILES: ${RESULTS_DIR}/compilable/hdrgen_dip1029.di
TEST_OUTPUT:
---
=== ${RESULTS_DIR}/compilable/hdrgen_dip1029.di
// D import file generated from 'compilable/hdrgen_dip1029.d'
module foo.bar.foobar.baz;
void foo();
throw void foobar();
nothrow void bar();
nothrow
{
throw void n_t();
void n();
}
void _t();
throw void t();
struct S
{
throw void foo();
}
class CA
{
void foo();
}
class CB : CA
{
override @nogc void foo();
}
nothrow
{
void t2();
throw nothrow void n2();
}
---
*/
module foo.bar.foobar.baz;

void foo() {}

void foobar() throw {}
void bar() nothrow {}

nothrow {
void n_t() throw;
void n();
}

void _t();
void t() throw;

struct S {
void foo() {
_t();
t();
n_t();
}
}

// class inheritance
class CA {
void foo() throw;
}

class CB : CA {
override void foo() @nogc;
}

nothrow:
void t2() throw;

throw:
void n2() nothrow;

0 comments on commit 5995579

Please sign in to comment.