Changeset 646

Show
Ignore:
Timestamp:
08/28/10 17:55:03 (1 year ago)
Author:
walter
Message:

Issue 4177 - ctfe can't be used in pure functions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/expression.c

    r645 r646  
    42764276            } 
    42774277 
    4278             /* If ANY of its enclosing functions are pure, 
    4279              * it cannot do anything impure. 
    4280              * If it is pure, it cannot access any mutable variables other 
    4281              * than those inside itself 
     4278            /* Magic variable __ctfe never violates pure or safe 
    42824279             */ 
    4283             if (hasPureParent && v->isDataseg() && 
    4284                 !v->isImmutable()) 
     4280            if (v->ident != Id::ctfe) 
    42854281            { 
    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                } 
    42984303            } 
    42994304