Article View: gnu.g++.bug
Article #667Can't assign 'this' in a constructor
From: Patrick Steranka
Date: Sat, 02 Dec 1989 22:31
Date: Sat, 02 Dec 1989 22:31
60 lines
2535 bytes
2535 bytes
In BS, pg 164, 5.5.6 it states:
The assignment to "this" [in a constructor function] informs
the compiler that the programmer has taken control and that the
default mechanism for allocating storage should not be used.
This does not seem to be supported by the GNU g++ compiler.
Instead, the error
assignment of read-only parameter `$this'
is produced. Below is a sample program and the output produced
when compiling it. This happens on a SUN 3/280 running SUN OS
3.5 using g++(1.36.1).
============================== ex7.cc ==============================
#include <stream.h>
class T{
char s[10];
public:
T() {
if (this == 0) this = (T*) 0x43;
cout << "Value of 'this' is " << (int)this << "\n";
};
~T() {
cout << "In ~T, the value of 'this' is " << (int)this << "\n";
this = 0;
}
};
main(int argc, char* argv[])
{
T a1;
}
============================== ex7.cc ==============================
==================== Output from compiling ex7.cc ====================
cd /usr.MC68020/zulu/patrick/test/c++/
make -k ex7
g++ -o ex7 -g -v ex7.cc
gcc version 1.36.1- (based on GCC 1.36)
/usr/local/lib/gnu/gcc/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 ex7.cc /usr/tmp/cca21893.cpp
GNU CPP version 1.36
/usr/local/lib/gnu/gcc/gcc-cc1plus /usr/tmp/cca21893.cpp -quiet -dumpbase ex7.cc -g -version -o /usr/tmp/cca21893.s
GNU C++ version 1.36.1 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36.
default target switches: -m68020 -mc68020 -m68881 -mbitfield
ex7.cc: In method T::T ():
ex7.cc:6: assignment of read-only parameter `$this'
*** Error code 1
make: Fatal error: Target `ex7' not remade because of errors
Compilation exited abnormally with code 1 at Sat Dec 2 17:25:34
==================== Output from compiling ex7.cc ====================
patrick (Patrick Steranka @ Corporation for Open Systems)
-- patrick@cos.com
-- patrick%cos.com@uunet.uu.net
-- {uunet, sundc, decuac, hqda-ai, hadron}!cos!patrick
Technical Details
Message-ID:
<8912022231.AA26818@qna.cos.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!cos.com!patrickShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!cos.com!patrick From: patrick@cos.com (Patrick Steranka) Newsgroups: gnu.g++.bug Subject: Can't assign 'this' in a constructor Message-ID: <8912022231.AA26818@qna.cos.com> Date: 2 Dec 89 22:31:38 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 60