home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.bug
- Path: sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!gte.com!steve%eowyn
- From: steve%eowyn@gte.com (Steve Preston)
- Subject: dtor call without ctor call on temp instance.
- Message-ID: <9211161929.AA02362@bunny.gte.com>
- Sender: gnulists@ai.mit.edu
- Organization: GNUs Not Usenet
- Distribution: gnu
- Date: Mon, 16 Nov 1992 09:31:18 GMT
- Approved: bug-gcc@prep.ai.mit.edu
- Lines: 49
-
- I tried mailing to bug-g++@prep.ai.mit.edu, but it bounced.
-
- For gcc (g++) versions 2.2.2 and 2.3.1, on hppa1.1-hp-hpux and on
- decstation-ultrix.
-
- When a class has (1) an operator= method, (2) a constructor and
- (3) destructor, calling the operator= method causes a destructor call
- on a temporary instance without a corresponding constructor call.
-
- For example:
-
- /* #include "String.h" */
-
- /* String.h */
- const int max_string_length = 128;
-
- class String {
- public:
- String();
- ~String();
-
- String operator=(const String &);
- int length() const;
- int read ();
- void print() const;
-
- private:
- char text[max_string_length+1];
- };
-
- main(int, char *[])
- {
- String s1, s2;
-
- s2 = s1;
-
- s1.print();
- s2.print();
-
- return 0;
- }
-
- After the assignment, the destructor is called on a temporary instance
- of String, without a corresponding constructor call.
-
- I believe this is a bug.
- --
- Steve Preston (spreston@gte.com)
-
-