Say we have an utility function:
std::string GetDescription() { return \"The description.\"; }
Is it OK to return the string literal? Is th
Is it OK to return the string literal? Is the implicitly created std::string object copied?
It is OK. What you get, is the (implicit) constructor for std::string, creating a local copy, returned then as a rvalue reference. Taking the result in client code into a string, will set that string from an rvalue reference.
If you use the second piece of code, you "say too much". The code is correct, and they are (almost) equivalent (they should be equivalent, but the optimizations that the compiler is permitted to perform in the first case are better*).
I would go for:
std::string GetDescription() { return std::string("The description."); }
This way it is explicit that you return a string, and the code is (almost) minimal: you rely on the std::string move-construction.
*) edited accordingly, after comment by @SteveJessop.