home *** CD-ROM | disk | FTP | other *** search
- #if 0
- From: Victor Griswold
- Subject: operator=()
- Status: Fixed in 3.0
- #endif
-
- // ZTC 3.0b7 ignores class type conversion operators when resolving
- // class assignment operators. This causes bit-image copies to be employed
- // for assignments instead of the the proper assignment operators declared
- // in the class. This worked correctly in all ZTC compilers 2.14-3.0b5, in
- // GCC, and in AT&T CC. The fault is utterly fatal for all my reference-
- // counting storage allocators.
- //
- // The following code SHOULD output:
- //
- // in s1::operator int()
- // in s1& operator=(int src)
- // in s1::operator int()
- // in s1& operator=(int src)
- // in s2& operator=(const s2 &src)
- // in s2::operator int()
- // in s2& operator=(int src)
- //
- // Instead, it outputs just:
- //
- // in s1::operator int()
- // in s1& operator=(int src)
- // in s2& operator=(const s2 &src)
- // in s2::operator int()
- // in s2& operator=(int src)
- //
- // This is because it performs an incorrect bit-image copy of the
- // assignment 'b = a'.
- //
-
- #include <stdio.h>
-
-
- struct s1 {
-
- int x;
-
- operator int() const;
-
- s1& operator=(int src);
- };
-
-
- s1::operator int() const {
- printf("in s1::operator int()\n");
- return x;
- }
-
-
- s1& s1::operator=(int src) {
- printf("in s1& operator=(int src)\n");
- x = src;
- return *this;
- }
-
-
-
-
- struct s2 {
- int x;
-
- operator int() const;
-
- s2& operator=(int src);
-
- s2& operator=(const s2 &src);
- };
-
-
- s2::operator int() const {
- printf("in s2::operator int()\n");
- return x;
- }
-
-
- s2& s2::operator=(int src) {
- printf("in s2& operator=(int src)\n");
- x = src;
- return *this;
- }
-
-
- s2& s2::operator=(const s2 &src) {
- printf("in s2& operator=(const s2 &src)\n");
- x = src.x;
- return *this;
- }
-
-
-
- int main() {
- s1 a, b;
- s2 c, d;
-
-
- a.x = 1;
- b.x = 2;
- c.x = 3;
- d.x = 4;
-
- b = a;
- b = int(a);
-
- d = c;
- d = int(c);
-
- return 0;
- }
-