[gnu.g++.bug] G++ 1.36 problem?

mthome@bbn.com (Mike Thome) (10/17/89)

Now that I've got g++ working here (thanks those who responded to my
earlier plea for help), I've got another problem...
The following code fragment (from InterViews):
  class Resource {
  public:
      Resource () { refcount = 1; }
      ~Resource () { if (--refcount > 0) { this = 0; } }
  
      void Reference () { ++refcount; }
      int LastRef () { return refcount == 1; }
  private:
      unsigned refcount;
  };

Generates the following error message:
  foo.c: In method Resource::~Resource ():
  foo.c:4: assignment of read-only parameter `$this'

As far as I can tell from Stroustrup, this appears to be a perfectly
valid use of THIS in a destructer.  What's going on here?

-mik (mthome@bbn.com, mthome@thalamus.bu.edu) 

schmidt@glacier.ics.uci.edu (Doug Schmidt) (10/17/89)

In article <46991@bbn.COM>, mthome@bbn (Mike Thome) writes:
>Now that I've got g++ working here (thanks those who responded to my
>earlier plea for help), I've got another problem...
>The following code fragment (from InterViews):
>  class Resource {
>  public:
>      Resource () { refcount = 1; }
>      ~Resource () { if (--refcount > 0) { this = 0; } }
>  
>      void Reference () { ++refcount; }
>      int LastRef () { return refcount == 1; }
>  private:
>      unsigned refcount;
>  };
>
>Generates the following error message:
>  foo.c: In method Resource::~Resource ():
>  foo.c:4: assignment of read-only parameter `$this'
>
>As far as I can tell from Stroustrup, this appears to be a perfectly
>valid use of THIS in a destructer.  What's going on here?

Assigning to this is an anachronism.  However, you can make g++
accept this via the -fthis-is-variable option.

Doug
--
Master Swordsman speak of humility;             | schmidt@ics.uci.edu (ARPA)
Philosophers speak of truth;                    | office: (714) 856-4034
Saints and wisemen speak of the Tao of no doubt;
The moon, sun, and sea speaks for itself. -- Hiroshi Hamada