All,
With the Solaris C++ compiler and our current "w-all" flags, calling a
non-const function on a temporary, as in
class C { ... void doSomething(); ... };
...
C().doSomething();
produces a
Warning, reftotemp: should not initialize a non-const reference
with a temporary.
[Note: This is similar to the error (not warning) you get on every
compiler (because it is Standard-mandated behavior) when passing a
temporary to a function via non-const reference, as in
class C { ... };
void f(C &);
...
f(C());
]
I personally encountered a handfull of places in the OOo code base were
this warning occured, mostly in places where it could well be solved by
making the offending function const. In none of those cases did it
point to a real problem in our code base. However, PL now stumbled over
boost/scoped_array.hpp, which includes offending code in the form of
void reset(T * p = 0)
{
this_type(p).swap(*this);
}
(and other, similar classes from boost probably have the same problem).
Instead of taking the hassle of patching the boost files in a way to
silence this warning, I would rather suggest to switch off this warning
globally.
[Some sort of personally biased rationale for switching that warning
off: For a start, I never quite understood the rationale behind
forbidding passing a temporary to a function via non-const
reference---C++ is generally a "shoot yourself in the foot if you feel
like it" language, and the safety-measure installed by this error does
not really fit that philosophy. Also, in both cases (the warning when
calling a non-const function on a temporary and the error when passing a
temporary to a function via non-const reference), there are functions
that have externally-visible side effects, or that modify state other
than the state of the temporary object, and so it can well make sense to
call them in the given scenarios.]
Another voice from the Sun Solaris C++ compiler group on this subject is
as follows: "In this example, T* is converted to a temporary
'this_type' object, and non-const member function swap is called on the
object. The warning tells you that you might not want to do that. The
C++ language definition has wobbled over time on whether calling a
non-const member function on a temp is allowed. I think the current
intention is to allow it. BTW, the +w2 option tends to give a lot of
warnings you don't want to know about. Its primary use is to check for
portability nits."
So, if there are no objections, I would switch off the reftotemp warning
globally for all unxsol platforms.
-Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]