Skip to content

Commit

Permalink
fix Issue 17049 - [scope] member methods not escape checked like free…
Browse files Browse the repository at this point in the history
… functions
  • Loading branch information
WalterBright authored and MartinNowak committed Mar 4, 2017
1 parent 06e4b94 commit ad366ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ddmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ extern (C++) class FuncDeclaration : Declaration
if (ad && ad.isClassDeclaration() && (tf.isreturn || sc.stc & STCreturn) && !(sc.stc & STCstatic))
sc.stc |= STCscope;

// If 'this' has no pointers, remove 'scope' as it has no meaning
if (sc.stc & STCscope && ad && ad.isStructDeclaration() && !ad.type.hasPointers())
{
sc.stc &= ~STCscope;
tf.isscope = false;
}

sc.linkage = linkage;

if (!tf.isNaked() && !(isThis() || isNested()))
Expand Down
34 changes: 34 additions & 0 deletions test/fail_compilation/retscope2.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,38 @@ fail_compilation/retscope2.d(614): Error: template instance retscope2.test600!(i
test600(p, q);
}

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

/*
TEST_OUTPUT:
---
fail_compilation/retscope2.d(719): Error: escaping reference to local variable s
fail_compilation/retscope2.d(721): Error: escaping reference to local variable s
---
*/

#line 700
// https://issues.dlang.org/show_bug.cgi?id=17049

@safe S700* get2(return ref scope S700 _this)
{
return &_this;
}

struct S700
{
@safe S700* get1() return scope
{
return &this;
}
}

S700* escape700(int i) @safe
{
S700 s;
if (i)
return s.get2(); // 719
else
return s.get1(); // 721
}

0 comments on commit ad366ab

Please sign in to comment.