I'm implementing some C++ static analysis rules, and one of them prohibits a function from returning a reference or pointer to a reference parameter of the function, i.e. the following are all non-compliant:

int *f(int&amp; x) { return &amp;x; } // #1
const int *g(const int&amp; x) { return &amp;x; } // #2
int&amp; h(int&amp; x) { return x; } // #3
const int&amp; m(const int&amp; x) { return x; } // #4


The justification given for this is that "It is implementation-defined behaviour whether the reference parameter is a temporary object or a reference to the parameter."

I'm puzzled by this, however, because stream operators in C++ are written in this way, e.g.

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const X&amp; x) {
    //...
    return os;
}


I think I'm pretty confident that stream operators in C++ do not in general exhibit implementation-defined behaviour, so what's going on?

According to my understanding as it is at present, I would expect #1 and #3 to be well-defined, on the basis that temporaries cannot be bound to non-const references, so int&amp; x refers to a real object that has lifetime beyond the scope of the function, hence returning a pointer or reference to that object is fine. I would expect #2 to be dodgy, because a temporary could have been bound to const int&amp; x, in which case trying to take its address would seem a bad plan. I'm not sure about #4 - my gut feeling is that that's also potentially dodgy, but I'm not sure. In particular, I'm not clear on what would happen in the following case:

const int&amp; m(const int&amp; x) { return x; }
//...
const int&amp; r = m(23);



Question: Is the molecule of hot water heavier than that of cold water?
Answer: According to http://www.verticallearning.org/curriculum/science/gr7/student/unit01/page05.html , the average velocity of a water molecule at 20C is approximately 590 m/s:



If you now calculate the difference in mass between water molecules "at rest" and moving at 590 m/s, this ratio is given by

$$\gamma=\sqrt{\left(1-\frac{v^2}{c^2}\right)}$$

Expanding this for the case where $v&lt;&lt;c$, we get

$$\frac{\delta m}{m} = \frac12\left(\frac{v}{c}\right)^2 \sim 2\cdot10^{-12}$$

The difference is there; it might be measurable; but it is very, very tiny. Any condensation on your colder sample will be many times heavier than the difference in mass.

Note that the above calculation is for "cool water" vs "water at absolute zero". The difference between "hot" and "cold" water will be even smaller. Also note that to do this calculation properly, you really need to evaluate the expression for $\gamma$ at every velocity, and integrate. This doesn't change the basic answer: "yes it changes; but it is a very very small change".