springning / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

need an action to hold an object and return its reference #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
gmock doesn't allow using Return(x) in a function that returns a
reference.  The reason is that it's likely a programmer error (a
reference of a *copy* of x will be returned, which may not be what the
programmer wants).

ReturnRef(x) can be used in this situation, but it doesn't save a copy
of x in the action object.  (It returns a reference to the original
x.)  So the user is responsible for managing the lifespan of x, which
often is inconvenient.

We should have an action ReturnRefOfCopy(x) which works like Return(x)
except that it can only be used in a function that returns a
reference.  The action object will save a copy of x, and return the
reference to the saved copy later.  Therefore the action is still
valid after x has gone out of scope.

Original issue reported on code.google.com by zhanyong...@gmail.com on 24 Nov 2009 at 10:44

GoogleCodeExporter commented 9 years ago
Bumps up priority, as this inconvenience has caused people to think that gmock
doesn't support functions that return a reference.

Original comment by w...@google.com on 5 Jun 2010 at 6:40

GoogleCodeExporter commented 9 years ago
Fixed in r306.

Original comment by w...@google.com on 3 Jul 2010 at 12:17