Hi,

Stephan Bergmann wrote:

  C().doSomething();

produces a

  Warning, reftotemp: should not initialize a non-const reference
  with a temporary.


[..]

[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.

The problem here are unintended/unforeseen implicit conversions. Combined with overloading this can cause code to compile in surprising, erroneous ways. The simple example would be:

void inc(int & val) { val++; }
void inc(long & val) { val++; }
void inc(double & val) { val++; }
void inc(std::string & val) { val.append("+1"); }

short s = 0;
unsigned int u = 0;
float f = 0;
const char * t = "0";

void inc_all()
{
   inc(s);
   inc(u);
   inc(f);
   inc(s);
}

This would compile flawlessly, but without the expected side effects.

But that argument doesn't apply when calling a member of a temporary, because implicit conversions aren't applied to the operands of a member access operator. I don't think that warning is useful (in almost all cases).

So, if there are no objections, I would switch off the reftotemp warning globally for all unxsol platforms.


+1

Ciao, Jörg

--
Joerg Barfurth              Sun Microsystems - Desktop - Hamburg
>>>>>>>>>>>>>>>>>> using std::disclaimer <<<<<<<<<<<<<<<<<<<<<<<
Software Engineer                         [EMAIL PROTECTED]
OpenOffice.org Configuration          http://util.openoffice.org


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to