Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -5182,7 +5182,6 @@ class ReturnStatement final : public Statement
public:
Expression* exp;
size_t caseDim;
FuncDeclaration* fesFunc;
ReturnStatement* syntaxCopy() override;
ReturnStatement* endsWithReturnStatement() override;
void accept(Visitor* v) override;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/funcsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2780,7 +2780,7 @@ void buildResultVar(FuncDeclaration fd, Scope* sc, Type tret)
if (sc && fd.vresult.semanticRun == PASS.initial)
{
TypeFunction tf = fd.type.toTypeFunction();
if (fd.isNRVO || tf.isRef)
if (tf.isRef)
fd.vresult.storage_class |= STC.ref_;
else if (target.isReturnOnStack(tf, fd.needThis()))
fd.vresult.nrvo = true;
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -975,12 +975,11 @@ private extern(C++) final class Semantic3Visitor : Visitor

if (funcdecl.vresult)
{
Scope* scret = rs.fesFunc ? rs.fesFunc._scope : sc2;

// Create: return (vresult = exp, vresult);
exp = new ConstructExp(rs.loc, funcdecl.vresult, exp);
exp = exp.expressionSemantic(scret);
exp.type = funcdecl.vresult.type;
exp = Expression.combine(exp, new VarExp(rs.loc, funcdecl.vresult));
exp = exp.expressionSemantic(sc2);

if (rs.caseDim)
exp = Expression.combine(exp, new IntegerExp(rs.caseDim));
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dmd/statement.d
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,6 @@ extern (C++) final class ReturnStatement : Statement
{
Expression exp;
size_t caseDim;
FuncDeclaration fesFunc; // nested function for foreach it is in

extern (D) this(Loc loc, Expression exp) @safe
{
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dmd/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ class ReturnStatement final : public Statement
public:
Expression *exp;
size_t caseDim;
FuncDeclaration *fesFunc; // nested function for foreach it is in

ReturnStatement *syntaxCopy() override;

Expand Down
4 changes: 0 additions & 4 deletions compiler/src/dmd/statementsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2481,12 +2481,8 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
//printf("ReturnStatement.dsymbolSemantic() %s\n", toChars(rs));

FuncDeclaration fd = sc.parent.isFuncDeclaration();

if (fd.fes)
{
rs.fesFunc = fd;
fd = fd.fes.func; // fd is now function enclosing foreach
}

auto tf = fd.type.isTypeFunction();

Expand Down
31 changes: 0 additions & 31 deletions compiler/test/runnable/foreach5.d
Original file line number Diff line number Diff line change
Expand Up @@ -1208,36 +1208,6 @@ void testLDC326()
}
}

/***************************************/
// https://github.com/dlang/dmd/issues/22629

struct Collection2
{
this(ref Collection2) {}

int opApply(int delegate(Collection2))
{
return 0;
}
}

Collection2 testForeach2(ref Collection2 level1, ref Collection2 level2)
{
foreach (first; level1) {
foreach (second; level2)
return second;
}

return Collection2();
}

void test22629()
{
Collection2 c1, c2;
testForeach2(c1, c2);
}


/***************************************/

int main()
Expand Down Expand Up @@ -1271,7 +1241,6 @@ int main()
test14653();
test17041();
testLDC326();
test22629();

printf("Success\n");
return 0;
Expand Down
24 changes: 0 additions & 24 deletions compiler/test/runnable/rvalue1.d
Original file line number Diff line number Diff line change
Expand Up @@ -286,41 +286,17 @@ struct V12
{
S12 s;
this(int) { s = S12(1); }
int opApply(int delegate(Object)) { return 0; }
}

S12 foo12()
{
return __rvalue(V12(1).s);
}

S12 bar12()
{
S12 s = S12(1); // NRVO
foreach (_; V12(1))
return s;
return s;
}

S12 baz12()
{
S12 s1 = S12(1);
S12 s2 = S12(1); // No NRVO
foreach (_; V12(1))
return s1;
return s2;
}

void test12()
{
S12 s = foo12();
assert(&s == s.ptr);

S12 s2 = bar12();
assert(&s2 == s2.ptr);

S12 s3 = baz12();
assert(&s3 == s3.ptr);
}

/********************************/
Expand Down
Loading