Why can this code run successfully in Code::block. The IDB just reports
warning: \"reference to local variable ‘tmp’ returned\",
C++ standard tells that binding a temporary object to a const reference extends the lifetime of the temporary to the lifetime of the reference itself. So the code should work on any standard-compliant compiler, but the practice itself is not really nice in my view.
If you do use your string a currently unused in your example as string a = getString("Hello World!") you would simply make a copy, and in case of const string& a = getString("Hello World!") my bet that you should never have your temporary garbaged.