void visit(NewExp *e) { if (e->member && !e->member->isNogc() && f->setGC()) { // @nogc-ness is already checked in NewExp::semantic return; } if (e->onstack) return; if (e->allocator) { if (!e->allocator->isNogc() && f->setGC()) { e->error("operator new in @nogc function %s may allocate", f->toChars()); err = true; return; } return; } if (f->setGC()) { e->error("cannot use 'new' in @nogc function %s", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "'new' causes GC allocation"); }
void visit(CatExp *e) { if (f->setGC()) { e->error("cannot use operator ~ in @nogc function %s", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "operator ~ may cause GC allocation"); }
void visit(AssocArrayLiteralExp *e) { if (!e->keys->dim) return; if (f->setGC()) { e->error("associative array literal in @nogc function %s may cause GC allocation", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "associative array literal may cause GC allocation"); }
void visit(AssignExp *e) { if (e->e1->op == TOKarraylength) { if (f->setGC()) { e->error("setting 'length' in @nogc function %s may cause GC allocation", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "setting 'length' may cause GC allocation"); } }
void visit(ArrayLiteralExp *e) { if (e->type->ty != Tarray || !e->elements || !e->elements->dim) return; if (f->setGC()) { e->error("array literal in @nogc function %s may cause GC allocation", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "array literal may cause GC allocation"); }
void visit(IndexExp* e) { Type *t1b = e->e1->type->toBasetype(); if (t1b->ty == Taarray) { if (f->setGC()) { e->error("indexing an associative array in @nogc function %s may cause GC allocation", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "indexing an associative array may cause GC allocation"); } }
void visit(DeleteExp *e) { if (e->e1->op == TOKvar) { VarDeclaration *v = ((VarExp *)e->e1)->var->isVarDeclaration(); if (v && v->onstack) return; // delete for scope allocated class object } if (f->setGC()) { e->error("cannot use 'delete' in @nogc function %s", f->toChars()); err = true; return; } f->printGCUsage(e->loc, "'delete' requires GC"); }