Homec4science

Googletest export

Authored by Abseil Team <absl-team@google.com> on Feb 5 2019, 18:18.

Description

Googletest export

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

Details

Committed
Gennadiy Civil <misterg@google.com>Feb 12 2019, 19:20
Pushed
trottetDec 4 2019, 13:52
Parents
R9484:dda0df3b0ac6: Googletest export
Branches
Unknown
Tags
Unknown

Event Timeline

Gennadiy Civil <misterg@google.com> committed R9484:28a96d1834dd: Googletest export (authored by Abseil Team <absl-team@google.com>).Feb 12 2019, 19:20