Showing with 42 additions and 7 deletions.
  1. +0 −6 src/hdrgen.c
  2. +3 −0 src/mtype.c
  3. +38 −0 test/runnable/test14874.d
  4. +1 −1 test/runnable/testscope2.d
6 changes: 0 additions & 6 deletions src/hdrgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,6 @@ class PrettyPrintVisitor : public Visitor
}
t->attributesApply(&pas, &PrePostAppendStrings::fp);

if (t->isreturn)
buf->writestring(" return");

t->inuse--;
}
void visitFuncIdentWithPrefix(TypeFunction *t, Identifier *ident, TemplateDeclaration *td, bool isPostfixStyle)
Expand Down Expand Up @@ -941,9 +938,6 @@ class PrettyPrintVisitor : public Visitor
}
parametersToBuffer(t->parameters, t->varargs);

if (t->isreturn)
buf->writestring("return ");

t->inuse--;
}

Expand Down
3 changes: 3 additions & 0 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -6161,6 +6161,9 @@ int TypeFunction::attributesApply(void *param, int (*fp)(void *, const char *),
if (isref) res = fp(param, "ref");
if (res) return res;

if (isreturn) res = fp(param, "return");
if (res) return res;

TRUST trustAttrib = trust;

if (trustAttrib == TRUSTdefault)
Expand Down
38 changes: 38 additions & 0 deletions test/runnable/test14874.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// REQUIRED_ARGS: -dip25

template indexOfReturn(T...)
{
static if (T.length == 0)
{
enum indexOfReturn = -1;
}
else static if (T[$ - 1] == "return")
{
enum indexOfReturn = T.length - 1;
}
else
{
enum indexOfReturn = indexOfReturn!(T[0..$-1]);
}
}

struct Test
{
int n;

ref int getN() return
{
return n;
}

int getNNonReturn()
{
return n;
}
}

void main()
{
assert(indexOfReturn!(__traits(getFunctionAttributes, Test.getN)) != -1);
assert(indexOfReturn!(__traits(getFunctionAttributes, Test.getNNonReturn)) == -1);
}
2 changes: 1 addition & 1 deletion test/runnable/testscope2.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void test3()
assert(SS.foo4.mangleof == "_D10testscope22SS4foo4MFNcNkKNgPiZi");

// Test scope pretty-printing
assert(typeof(SS.foo1).stringof == "ref int(return ref int delegate() return p)return ");
assert(typeof(SS.foo1).stringof == "ref return int(return ref int delegate() return p)");
assert(typeof(SS.foo2).stringof == "ref int(return ref int delegate() p)");
assert(typeof(SS.foo3).stringof == "ref int(return ref inout(int*) p)");
assert(typeof(SS.foo4).stringof == "ref int(return ref inout(int*) p)");
Expand Down