Compiling with GCC 6 lead to segfaults in unit tests written using
the gmock and gtest, because it invoked undefined behavior.
When optimizing, GCC assumes the 'this' pointer can never be null.
In the ActionResultHolder template, methods returned
null pointers and it caused segfaults. These null pointers were
replaced with pointers to dynamically created pointers to the
ActionResultHolder objects.
Source of patch:
https://github.com/google/googletest/issues/705
https://github.com/google/googletest/issues/705#issuecomment-
235067917
Change-Id: Id617519921a0b6bdc3df01e417d762028ec132c7
template <>
class ActionResultHolder<void> : public UntypedActionResultHolderBase {
public:
+ explicit ActionResultHolder() {}
+
void GetValueAndDelete() const { delete this; }
virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
const typename Function<F>::ArgumentTuple& args,
const string& call_description) {
func_mocker->PerformDefaultAction(args, call_description);
- return NULL;
+ return new ActionResultHolder();
}
// Performs the given action and returns NULL.
const Action<F>& action,
const typename Function<F>::ArgumentTuple& args) {
action.Perform(args);
- return NULL;
+ return new ActionResultHolder();
}
};