Skip to content

Commit

Permalink
fix Issue 14547 - Ddoc should prefer new Variable Template syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed May 8, 2015
1 parent ae58a9f commit b541d1c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/doc.c
Expand Up @@ -140,6 +140,8 @@ static Dsymbol *getEponymousMember(TemplateDeclaration *td)
return ad;
if (FuncDeclaration *fd = td->onemember->isFuncDeclaration())
return fd;
if (VarDeclaration *vd = td->onemember->isVarDeclaration())
return td->constraint ? NULL : vd;

return NULL;
}
Expand Down Expand Up @@ -1096,6 +1098,9 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
buf->writestring("immutable ");
if (d->isSynchronized())
buf->writestring("synchronized ");

if (d->storage_class & STCmanifest)
buf->writestring("enum ");
}
}
}
Expand Down Expand Up @@ -1129,6 +1134,21 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
else
buf->writestring(d->ident->toChars());

if (d->isVarDeclaration() && td)
{
buf->writeByte('(');
if (td->origParameters && td->origParameters->dim)
{
for (size_t i = 0; i < td->origParameters->dim; i++)
{
if (i)
buf->writestring(", ");
toCBuffer((*td->origParameters)[i], buf, &hgs);
}
}
buf->writeByte(')');
}

// emit constraints if declaration is a templated declaration
if (td && td->constraint)
{
Expand Down
33 changes: 33 additions & 0 deletions test/compilable/ddoc10.d
Expand Up @@ -175,3 +175,36 @@ struct T
///
this(int){}
}


// 14547

/// doc-comment
int x14547 = 1;

/// ditto
enum int y14547 = 2;

/// doc-comment
enum isInt14547(T) = is(T == int);

/// ditto
enum bool isString14547(T) = is(T == string);

/// ditto
static immutable typeName14547(T) = T.stringof;

/// ditto
int storageFor14547(T) = 0;

/// doc-comment
template foo14547(T)
{
enum int foo14547 = T.stringof.length;
}

/// ditto
template bar14547(T) if (is(T == int))
{
enum int bar14547 = T.stringof.length;
}
19 changes: 19 additions & 0 deletions test/compilable/extra-files/ddoc10.html
Expand Up @@ -135,6 +135,25 @@ <h1>ddoc10</h1>
<dd><br><br>
</dd>
</dl>
</dd>
<dt><big><a name="x14547"></a>int <u>x14547</u>;
<br><a name="y14547"></a>enum int <u>y14547</u>;
</big></dt>
<dd>doc-comment<br><br>

</dd>
<dt><big><a name="isInt14547"></a>enum <u>isInt14547</u>(T);
<br><a name="isString14547"></a>enum bool <u>isString14547</u>(T);
<br><a name="typeName14547"></a>static immutable <u>typeName14547</u>(T);
<br><a name="storageFor14547"></a>int <u>storageFor14547</u>(T);
</big></dt>
<dd>doc-comment<br><br>

</dd>
<dt><big><a name="foo14547"></a>enum int <u>foo14547</u>(T);
<br><a name="bar14547"></a>template <u>bar14547</u>(T) if (is(T == int))</big></dt>
<dd>doc-comment<br><br>

</dd>
</dl>

Expand Down

0 comments on commit b541d1c

Please sign in to comment.