| 4286 | | error("pure function '%s' cannot access mutable static data '%s'", |
|---|
| 4287 | | sc->func->toChars(), v->toChars()); |
|---|
| 4288 | | } |
|---|
| 4289 | | else if (sc->func->isPure() && |
|---|
| 4290 | | sc->parent->pastMixin() != v->parent->pastMixin() && |
|---|
| 4291 | | !v->isImmutable() && |
|---|
| 4292 | | !(v->storage_class & STCmanifest)) |
|---|
| 4293 | | { |
|---|
| 4294 | | error("pure nested function '%s' cannot access mutable data '%s'", |
|---|
| 4295 | | sc->func->toChars(), v->toChars()); |
|---|
| 4296 | | if (v->isEnumDeclaration()) |
|---|
| 4297 | | error("enum"); |
|---|
| | 4282 | /* If ANY of its enclosing functions are pure, |
|---|
| | 4283 | * it cannot do anything impure. |
|---|
| | 4284 | * If it is pure, it cannot access any mutable variables other |
|---|
| | 4285 | * than those inside itself |
|---|
| | 4286 | */ |
|---|
| | 4287 | if (hasPureParent && v->isDataseg() && |
|---|
| | 4288 | !v->isImmutable()) |
|---|
| | 4289 | { |
|---|
| | 4290 | error("pure function '%s' cannot access mutable static data '%s'", |
|---|
| | 4291 | sc->func->toChars(), v->toChars()); |
|---|
| | 4292 | } |
|---|
| | 4293 | else if (sc->func->isPure() && |
|---|
| | 4294 | sc->parent->pastMixin() != v->parent->pastMixin() && |
|---|
| | 4295 | !v->isImmutable() && |
|---|
| | 4296 | !(v->storage_class & STCmanifest)) |
|---|
| | 4297 | { |
|---|
| | 4298 | error("pure nested function '%s' cannot access mutable data '%s'", |
|---|
| | 4299 | sc->func->toChars(), v->toChars()); |
|---|
| | 4300 | if (v->isEnumDeclaration()) |
|---|
| | 4301 | error("enum"); |
|---|
| | 4302 | } |
|---|
| 4298 | 4303 | } |
|---|
| 4299 | 4304 | |
|---|
| 4300 | 4305 | /* Do not allow safe functions to access __gshared data |
|---|
| 4301 | 4306 | */ |
|---|
| 4302 | 4307 | if (sc->func->isSafe() && v->storage_class & STCgshared) |
|---|
| 4303 | 4308 | error("safe function '%s' cannot access __gshared data '%s'", |
|---|
| 4304 | 4309 | sc->func->toChars(), v->toChars()); |
|---|
| 4305 | 4310 | } |
|---|
| 4306 | 4311 | #else |
|---|
| 4307 | 4312 | if (sc->func && sc->func->isPure() && !sc->intypeof) |
|---|
| 4308 | 4313 | { |
|---|
| 4309 | 4314 | if (v->isDataseg() && !v->isImmutable()) |
|---|
| 4310 | 4315 | error("pure function '%s' cannot access mutable static data '%s'", sc->func->toChars(), v->toChars()); |
|---|
| 4311 | 4316 | } |
|---|
| 4312 | 4317 | #endif |
|---|
| 4313 | 4318 | #endif |
|---|
| 4314 | 4319 | } |
|---|
| 4315 | 4320 | #if 0 |
|---|
| 4316 | 4321 | else if ((fd = var->isFuncLiteralDeclaration()) != NULL) |
|---|
| 4317 | 4322 | { Expression *e; |
|---|