Generally compilers are not obligated to do NRVO (Named Return Value Optimization) aka copy elision even if the certain criteria that allow it are met. Nor a program must be depended on such optimizations as it makes it effectively non portable.
Now, as far as it concerns the first case, the answer is yes, the compiler is permitted to optimize away the copy of the vector. In particular this case falls in the following wording of the standard 12.8/p31.1 Copying and moving class objects [class.copy]:
... elision of copy/move operations, called copy elision, is permitted in
the following circumstances (which may be combined to eliminate
multiple copies):
(31.1) — in a return statement in a function with a
class return type, when the expression is the name of a nonvolatile
automatic object (other than a function parameter or a variable
introduced by the exceptiondeclaration of a handler (15.3)) with the
same type (ignoring cv-qualification) as the function return type, the
copy/move operation can be omitted by constructing the automatic
object directly into the function’s return value.
Also, from C++11 and beyond std::vector
has move facilities and actually the vector
is going to be moved.
As far as it concerns the second case the answer is no. And after all there's no need to, since you pass a reference to the vector. That is, you pass an alias of the vector (i.e. the object itself).