Support ref-qualified member functions in Property().

This commit is contained in:
Roman Perepelitsa
2017-08-22 16:06:26 +02:00
parent 675686a139
commit 966b549c88
2 changed files with 47 additions and 8 deletions

View File

@@ -3588,10 +3588,15 @@ class AClass {
// A getter that returns a reference to const.
const std::string& s() const { return s_; }
#if GTEST_LANG_CXX11
const std::string& s_ref() const & { return s_; }
#endif
void set_s(const std::string& new_s) { s_ = new_s; }
// A getter that returns a reference to non-const.
double& x() const { return x_; }
private:
int n_;
std::string s_;
@@ -3635,6 +3640,21 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
EXPECT_FALSE(m.Matches(a));
}
#if GTEST_LANG_CXX11
// Tests that Property(&Foo::property, ...) works when property() is
// ref-qualified.
TEST(PropertyTest, WorksForRefQualifiedProperty) {
Matcher<const AClass&> m = Property(&AClass::s_ref, StartsWith("hi"));
AClass a;
a.set_s("hill");
EXPECT_TRUE(m.Matches(a));
a.set_s("hole");
EXPECT_FALSE(m.Matches(a));
}
#endif
// Tests that Property(&Foo::property, ...) works when property()
// returns a reference to non-const.
TEST(PropertyTest, WorksForReferenceToNonConstProperty) {