home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: Destruction of temporaries
- Message-ID: <1992Sep2.042030.488@frumious.uucp>
- Date: Wed, 2 Sep 1992 04:20:30 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <rmartin.715101472@thor> <1992Aug29.184025.328@frumious.uucp> <rmartin.715267769@thor>
- Organization: None
- Lines: 38
-
- rmartin@thor.Rational.COM (Bob Martin) writes:
- |Some compilers may wish to deal with the deluge of warnings by
- |implementing #pragmas which specifically inhibit warnings about the
- |creation of aliases as arguments to specific functions. For example:
- |
- | #pragma Supress_Alias_Warning String::operator+(const String&, const String&)
- |
- |This could prevent the compiler from warning about aliases created
- |when forming the arguments to functions which are known to be benign.
- |The above #pragma would eliminate all the warnings from your example,
- |but would still pass warnings about other aliases.
- |
- |This exposes the alias problem, and puts responsibility for it square
- |on the programmer. It also allows the compiler to destroy temporaries
- |at the earliest possible moment.
-
- In my code, and I suspect in most people's, the vast majority of
- reference parameters to functions fall into one of two categories.
- Either it's a reference to non-const, and can't be called with a
- temporary for an argument, or it's a reference to const and it's
- perfectly safe to call it with a temporary argument.
-
- So I think it would be a better idea for the programmer to identify
- those functions which can't be called with temporaries as arguments,
- instead of those which can. As, for example, in Eric Smith's
- proposal upon which I commented in another posting.
-
- One might argue that it is safer to treat functions as 'dangerous
- to call with temporary arguments unless otherwise indicated', rather
- than 'safe ... unless otherwise indicated'. But I think this argument
- ignores human nature. If you ask people to flag 19 out of every 20
- functions (numbers made up out of thin air) as safe, many of them
- will get tired of that and just start ignoring the warning messages.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-