Thread View: gnu.g++.bug
3 messages
3 total messages
Started by Patrick Steranka
Sat, 02 Dec 1989 22:31
Can't assign 'this' in a constructor
Author: 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
Re: Can't assign 'this' in a constructor
Author: Doug Schmidt
Date: Sat, 02 Dec 1989 23:08
Date: Sat, 02 Dec 1989 23:08
20 lines
1272 bytes
1272 bytes
In article <8912022231.AA26818@qna.cos.com>, patrick@cos (Patrick Steranka) writes: >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' try using the -fthis-is-variable flag. Doug -- Any man's death diminishes me, | schmidt@ics.uci.edu (ARPA) Because I am involved in Mankind; | office: (714) 856-4043 And therefore never send to know for whom the bell tolls; It tolls for thee -- John Donne
Can't assign 'this' in a constructor
Author: Michael Tiemann
Date: Sat, 02 Dec 1989 23:25
Date: Sat, 02 Dec 1989 23:25
8 lines
910 bytes
910 bytes
If you want to assign to `this', you must use the flag -fthis-is-variable. The 2.0 language spec permits GNU C++ to be picky about this matter, though it suggests compiler writers go easy on their users by giving the a flag whereby original behavior is restored. GNU C++ has never allowed `this' to be assigned outside of constructors and destructors, so there is no behvior to restore there. Michael
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads