Mercurial > projects > ddmd
diff dmd/VarExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | e28b18c23469 |
children | af1bebfd96a4 |
line wrap: on
line diff
--- a/dmd/VarExp.d Sun Sep 05 15:32:22 2010 +0400 +++ b/dmd/VarExp.d Thu Sep 09 22:51:44 2010 +0100 @@ -83,8 +83,22 @@ v.checkNestedReference(sc, loc); version (DMDV2) { static if (true) { - if (sc.func) + if (sc.func && !sc.intypeof) { + /* Given: + * void f() + * { int fx; + * pure void g() + * { int gx; + * void h() + * { int hx; + * void i() { } + * } + * } + * } + * i() can modify hx and gx but not fx + */ + /* Determine if sc.func is pure or if any function that * encloses it is also pure. */ @@ -107,17 +121,23 @@ * If it is pure, it cannot access any mutable variables other * than those inside itself */ - if (hasPureParent && !sc.intypeof && v.isDataseg() && !v.isInvariant()) + if (hasPureParent && v.isDataseg() && !v.isInvariant()) { error("pure function '%s' cannot access mutable static data '%s'", sc.func.toChars(), v.toChars()); } - else if (sc.func.isPure() && sc.parent != v.parent && !sc.intypeof && !v.isInvariant() && !(v.storage_class & STC.STCmanifest)) + else if (sc.func.isPure() && sc.parent != v.parent && !v.isInvariant() && !(v.storage_class & STC.STCmanifest)) { error("pure nested function '%s' cannot access mutable data '%s'", sc.func.toChars(), v.toChars()); if (v.isEnumDeclaration()) error("enum"); - } + } + + /* Do not allow safe functions to access __gshared data + */ + if (sc.func.isSafe() && v.storage_class & STCgshared) + error("safe function '%s' cannot access __gshared data '%s'", + sc.func.toChars(), v.toChars()); } } else { if (sc.func && sc.func.isPure() && !sc.intypeof)