Changeset 378
- Timestamp:
- 02/12/10 06:54:07 (15 years ago)
- Files:
-
- trunk/src/expression.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/expression.c
r375 r378 7741 7741 return e; 7742 7742 } 7743 7743 7744 7744 // Struct casts are possible only when the sizes match 7745 7745 if (tob->ty == Tstruct || t1b->ty == Tstruct) 7746 7746 { 7747 7747 size_t fromsize = t1b->size(loc); 7748 7748 size_t tosize = tob->size(loc); 7749 7749 if (fromsize != tosize) 7750 7750 { 7751 7751 error("cannot cast from %s to %s", e1->type->toChars(), to->toChars()); 7752 7752 return new ErrorExp(); 7753 7753 } 7754 7754 } 7755 7755 } 7756 7756 else if (!to) 7757 7757 { error("cannot cast tuple"); 7758 7758 to = Type::terror; 7759 7759 } 7760 7760 7761 if (!e1->type) 7762 { error("cannot cast %s", e1->toChars()); 7763 return new ErrorExp(); 7764 } 7765 7761 7766 #if 1 7762 7767 if (sc->func && sc->func->isSafe() && !sc->intypeof) 7763 7768 #else 7764 7769 if (global.params.safe && !sc->module->safe && !sc->intypeof) 7765 7770 #endif 7766 7771 { // Disallow unsafe casts 7767 7772 Type *tob = to->toBasetype(); 7768 7773 Type *t1b = e1->type->toBasetype(); 7769 7774 if (!t1b->isMutable() && tob->isMutable()) 7770 7775 { // Cast not mutable to mutable 7771 7776 Lunsafe: 7772 7777 error("cast from %s to %s not allowed in safe code", e1->type->toChars(), to->toChars()); 7773 7778 } 7774 7779 else if (t1b->isShared() && !tob->isShared()) 7775 7780 // Cast away shared 7776 7781 goto Lunsafe; 7777 7782 else if (tob->ty == Tpointer) 7778 7783 { if (t1b->ty != Tpointer) 7779 7784 goto Lunsafe; 7780 7785 Type *tobn = tob->nextOf()->toBasetype();
