home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
- From: pjl@cs.uiuc.edu (Paul Lucas)
- Subject: Re: What is this CFRONT 3.0 warning message trying to tell me?
- Message-ID: <BzF8yn.29o@cs.uiuc.edu>
- Sender: news@cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <1992Dec15.183649.20994@delfin.com>
- Distribution: usa
- Date: Thu, 17 Dec 1992 20:59:11 GMT
- Lines: 67
-
- In <1992Dec15.183649.20994@delfin.com> mr@delfin.com (Mark Rosenberg) writes:
-
- >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 );
- >};
-
- *****> Because this ^^^^^^^^^^^^^ isn't const.
-
- Thing const &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
-
- *****> No it shouldn't; your program will die a horrible death if it does.
- Thou shalt not return a reference to a local variable.
-
- >stdio is really bad style but I don't understand why the first call to
- >getThing generates a warning but the second doesn't.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-