In summary, looking at code like this

 B& b = c->foo();
 ...
 b.m();

If c->foo() returns a temporary ("return B();"), then it is safe.

Maybe I'm wrong, but are you completely sure about this one? I would say that the temporary object created in return B() will cease to exist as soon as it returns (just after the constructor finishes). So you will be returning a reference to a temporary which, I think, no longer is valid. I made a quick test to be sure and the destructor of B is indeed called. Why is it safe?