nagyistoce / googlemock

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

Return(x) should convert x to the desired type early #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When Return(x) is used in an action that returns type T, where x has type
U, x is not converted to type T until the action is actually performed. 
This has two problems:

1. the U => T conversion is done _every_ time the action is performed; in
general it's more efficient to do the conversion only once.

2. if the conversion depends on values that go out of scope after the
EXPECT_CALL() finishes, it won't work. e.g.

  // Bar() returns type T.  Foo(v) returns type U.  Conversion from
  // Foo(v) to U requires v to be alive.
  EXPECT_CALL(mock, Bar()).WillRepeatedly(Return(Foo(v)));
  ... v goes out of scope here ...
  mock.Bar();  // Crash!

I give this a high priority, as the later we fix this, the harder it gets
(as it's more likely the change will break existing clients).

Original issue reported on code.google.com by zhanyong...@gmail.com on 3 Nov 2009 at 12:45

GoogleCodeExporter commented 9 years ago
Fixed in r235.

Original comment by vladlosev on 24 Nov 2009 at 12:07