Re: Why is there no input value optimization?
0xCDCDCDCD@gmx.at (Martin B.) wrote (abridged):
However, what I would like to raise as a QOI question is, why can't
we have (or do we?) a proper compiler warning when the compiler
detects that the passed-by-value parameter isn't modified at all and
really should have been passed by const-reference?
I would not want such a warning. There are too many cases where
passing a copy is preferred.
For example, passing an int by const reference is almost certainly
worse for performance. So, probably, is passing a pair of ints, or a
pair of pointers. If the warning depends on the size of the object,
than making a class use the pImpl idiom could trigger the warning, as
could other implementation changes.
You should consider the issue of aliasing. It may be cheaper to pass a
4-int rectangle by const reference, but using it may be more expensive
because it's harder for the compiler to be sure it is not changed
through an alias.
Another issue is the need for a standard interface, for
polymorphism. Some overrides of a virtual function might change their
arguments, and others might not.
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]