| 4269 | 4269 | hasPureParent = true; |
|---|
| 4270 | 4270 | break; |
|---|
| 4271 | 4271 | } |
|---|
| 4272 | 4272 | Dsymbol *parent = outerfunc->toParent2(); |
|---|
| 4273 | 4273 | if (!parent) |
|---|
| 4274 | 4274 | break; |
|---|
| 4275 | 4275 | outerfunc = parent->isFuncDeclaration(); |
|---|
| 4276 | 4276 | } |
|---|
| 4277 | 4277 | |
|---|
| 4278 | 4278 | /* If ANY of its enclosing functions are pure, |
|---|
| 4279 | 4279 | * it cannot do anything impure. |
|---|
| 4280 | 4280 | * If it is pure, it cannot access any mutable variables other |
|---|
| 4281 | 4281 | * than those inside itself |
|---|
| 4282 | 4282 | */ |
|---|
| 4283 | 4283 | if (hasPureParent && v->isDataseg() && |
|---|
| 4284 | 4284 | !v->isImmutable()) |
|---|
| 4285 | 4285 | { |
|---|
| 4286 | 4286 | error("pure function '%s' cannot access mutable static data '%s'", |
|---|
| 4287 | 4287 | sc->func->toChars(), v->toChars()); |
|---|
| 4288 | 4288 | } |
|---|
| 4290 | 4291 | !v->isImmutable() && |
|---|
| 4291 | 4292 | !(v->storage_class & STCmanifest)) |
|---|
| 4292 | 4293 | { |
|---|
| 4293 | 4294 | error("pure nested function '%s' cannot access mutable data '%s'", |
|---|
| 4294 | 4295 | sc->func->toChars(), v->toChars()); |
|---|
| 4295 | 4296 | if (v->isEnumDeclaration()) |
|---|
| 4296 | 4297 | error("enum"); |
|---|
| 4297 | 4298 | } |
|---|
| 4298 | 4299 | |
|---|
| 4299 | 4300 | /* Do not allow safe functions to access __gshared data |
|---|
| 4300 | 4301 | */ |
|---|
| 4301 | 4302 | if (sc->func->isSafe() && v->storage_class & STCgshared) |
|---|
| 4302 | 4303 | error("safe function '%s' cannot access __gshared data '%s'", |
|---|
| 4303 | 4304 | sc->func->toChars(), v->toChars()); |
|---|
| 4304 | 4305 | } |
|---|
| 4305 | 4306 | #else |
|---|
| 4306 | 4307 | if (sc->func && sc->func->isPure() && !sc->intypeof) |
|---|
| 4307 | 4308 | { |
|---|
| 4308 | 4309 | if (v->isDataseg() && !v->isImmutable()) |
|---|
| 4309 | 4310 | error("pure function '%s' cannot access mutable static data '%s'", sc->func->toChars(), v->toChars()); |
|---|