home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!delfin.com!delfin.com!mr
- From: mr@delfin.com (Mark Rosenberg)
- Newsgroups: comp.lang.c++
- Subject: What is this CFRONT 3.0 warning message trying to tell me?
- Message-ID: <1992Dec15.183649.20994@delfin.com>
- Date: 15 Dec 92 18:36:49 GMT
- Sender: mr@yang (Mark Rosenberg)
- Reply-To: mark@delfin.com
- Organization: Delfin Systems, Sunnyvale CA
- Lines: 58
- Nntp-Posting-Host: merlin
-
- I'm porting a large application from a CFRONT 2.1-based compiler (Sun) to
- a CFRONT 3.0-based compiler (Solbourne). The following warning message
- has me somewhat mystified:
-
- "main.cc", line 31: warning: temporary used for non-const Thing& argument; no changes will be propagated to actual argument (anachronism)
-
- I've boiled the offending code down to:
-
- #include <string.h>
- #include <malloc.h>
- #include <stdio.h>
- class Thing
- {
- public:
-
- char *str;
- Thing(){ str = (char *)0; };
- Thing(char *s){str=strdup(s);};
- Thing &operator = ( Thing & rhs );
- };
-
- Thing &
- Thing::operator = ( Thing & rhs )
- {
- if( this->str )free( this->str );
- strcpy( this->str, rhs.str );
- return *this;
- }
-
- Thing getThing()
- {
- Thing t("a thing");
- return t;
- }
-
- main()
- {
- Thing t1("");
- t1 = getThing(); // warning
- printf("value: %s\n", t1.str );
-
- Thing t2 = getThing(); // no warning
- printf("value: %s\n", t2.str );
- }
-
- When this program is run you get the expectable result:
-
- value: a thing
- value: a thing
-
- I realize that getThing should really return a reference and that using
- stdio is really bad style but I don't understand why the first call to
- getThing generates a warning but the second doesn't.
- --
- Mark Rosenberg
- internet:mark@delfin.com
- phone: (408) 562-1126 fax: (408) 748-1140
- snail: Delfin Systems, 3000 Patrick Henry Drive, Santa Clara, CA 95054-1814
-