28a96d1834
Fix matcher comparisons for std::reference_wrapper. The googletest docs indicate that std::reference_wrapper should be used to for objects that should not be copied by the matcher (in fact, the ByRef() function is basically the same as a call to std::cref). However, for many types (such as std::string), the overloaded operator== will not resolve correctly. Specifically, this is problematic if operator== depends on template argument deduction, where the same type is named on LHS and RHS. Because template argument deduction happens before any implict conversions for purposes of overload resolution, attempting to compare T with std::reference_wrapper<T> simply looks like a comparison of unlike types. For exapmle, std::reference_wrapper<std::string> is implicitly convertible to 'const std::string&', which would be able to choose an overload specialization of operator==. However, the implicit conversion can only happen after template argument deduction for operator==, so a specialization that would other be an applicable overload is never considered. Note also that this change only affects matchers. There are good reasons that matchers may need to transparently hold a std::reference_wrapper. Other comparisons (like EXPECT_EQ, et. al.) don't need to capture a reference: they don't need to defer evaluation (as in googlemock), and they don't need to avoid copies (as the call chain of matchers does). PiperOrigin-RevId: 232499175 |
||
---|---|---|
.. | ||
BUILD.bazel | ||
gmock_all_test.cc | ||
gmock_ex_test.cc | ||
gmock_leak_test_.cc | ||
gmock_leak_test.py | ||
gmock_link_test.cc | ||
gmock_link_test.h | ||
gmock_link2_test.cc | ||
gmock_output_test_.cc | ||
gmock_output_test_golden.txt | ||
gmock_output_test.py | ||
gmock_stress_test.cc | ||
gmock_test_utils.py | ||
gmock_test.cc | ||
gmock-actions_test.cc | ||
gmock-cardinalities_test.cc | ||
gmock-function-mocker_nc_test.py | ||
gmock-function-mocker_nc.cc | ||
gmock-function-mocker_test.cc | ||
gmock-generated-actions_test.cc | ||
gmock-generated-function-mockers_test.cc | ||
gmock-generated-matchers_test.cc | ||
gmock-internal-utils_test.cc | ||
gmock-matchers_test.cc | ||
gmock-more-actions_test.cc | ||
gmock-nice-strict_test.cc | ||
gmock-port_test.cc | ||
gmock-pp_test.cc | ||
gmock-pp-string_test.cc | ||
gmock-spec-builders_test.cc |