mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 13:40:11 +03:00
Fix 23168 - return scope wrongly rewritten for structs with no indirections
This commit is contained in:
parent
3c1bfdcea7
commit
5d5fe27b8a
2 changed files with 44 additions and 0 deletions
|
@ -728,6 +728,11 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
|
||||||
else if (!dsym.type.hasPointers())
|
else if (!dsym.type.hasPointers())
|
||||||
{
|
{
|
||||||
dsym.storage_class &= ~STC.scope_; // silently ignore; may occur in generic code
|
dsym.storage_class &= ~STC.scope_; // silently ignore; may occur in generic code
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=23168
|
||||||
|
if (dsym.storage_class & STC.returnScope)
|
||||||
|
{
|
||||||
|
dsym.storage_class &= ~(STC.return_ | STC.returnScope);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3208,10 +3213,19 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
|
||||||
sc.stc |= STC.scope_;
|
sc.stc |= STC.scope_;
|
||||||
|
|
||||||
// If 'this' has no pointers, remove 'scope' as it has no meaning
|
// If 'this' has no pointers, remove 'scope' as it has no meaning
|
||||||
|
// Note: this is already covered by semantic of `VarDeclaration` and `TypeFunction`,
|
||||||
|
// but existing code relies on `hasPointers()` being called here to resolve forward references:
|
||||||
|
// https://github.com/dlang/dmd/pull/14232#issuecomment-1162906573
|
||||||
if (sc.stc & STC.scope_ && ad && ad.isStructDeclaration() && !ad.type.hasPointers())
|
if (sc.stc & STC.scope_ && ad && ad.isStructDeclaration() && !ad.type.hasPointers())
|
||||||
{
|
{
|
||||||
sc.stc &= ~STC.scope_;
|
sc.stc &= ~STC.scope_;
|
||||||
tf.isScopeQual = false;
|
tf.isScopeQual = false;
|
||||||
|
if (tf.isreturnscope)
|
||||||
|
{
|
||||||
|
sc.stc &= ~(STC.return_ | STC.returnScope);
|
||||||
|
tf.isreturn = false;
|
||||||
|
tf.isreturnscope = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.linkage = funcdecl._linkage;
|
sc.linkage = funcdecl._linkage;
|
||||||
|
|
30
test/compilable/test23168.d
Normal file
30
test/compilable/test23168.d
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=23168
|
||||||
|
// Issue 23168 - [DIP1000] return scope wrongly rewritten for structs with no indirections
|
||||||
|
|
||||||
|
@safe:
|
||||||
|
struct Ptr
|
||||||
|
{
|
||||||
|
int* fun() return scope { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int* funf(ref return scope Ptr p) { return null; }
|
||||||
|
|
||||||
|
int* use()
|
||||||
|
{
|
||||||
|
Ptr ptr;
|
||||||
|
return ptr.fun;
|
||||||
|
return funf(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent forward reference 'regression'
|
||||||
|
// See https://github.com/dlang/dmd/pull/14232#issuecomment-1162906573
|
||||||
|
struct S
|
||||||
|
{
|
||||||
|
void f() scope {}
|
||||||
|
alias x = _get_value;
|
||||||
|
|
||||||
|
static if (true)
|
||||||
|
int _get_value() {return 3;}
|
||||||
|
else
|
||||||
|
int _get_value() {return 4;}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue