Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
19a3bbce
Commit
19a3bbce
authored
Oct 22, 2019
by
Piotr Nycz
Browse files
Added tests verifying that temporaries are accepted by ReturnRef
Issue no 2527
parent
b11fb80e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
googlemock/test/gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+24
-0
No files found.
googlemock/test/gmock-actions_test.cc
View file @
19a3bbce
...
@@ -646,6 +646,30 @@ TEST(ReturnRefTest, IsCovariant) {
...
@@ -646,6 +646,30 @@ TEST(ReturnRefTest, IsCovariant) {
EXPECT_EQ
(
&
derived
,
&
a
.
Perform
(
std
::
make_tuple
()));
EXPECT_EQ
(
&
derived
,
&
a
.
Perform
(
std
::
make_tuple
()));
}
}
namespace
{
template
<
typename
T
,
typename
=
decltype
(
ReturnRef
(
std
::
declval
<
T
&&
>()))
>
bool
CanCallReturnRef
(
T
&&
)
{
return
true
;
}
bool
CanCallReturnRef
(
Unused
)
{
return
false
;
}
}
// Tests that ReturnRef(v) is not working with temporaries (T&&)
TEST
(
ReturnRefTest
,
WillNotAcceptTemporaryAkaRValueRef
)
{
int
value
=
13
;
EXPECT_TRUE
(
CanCallReturnRef
(
value
));
EXPECT_FALSE
(
CanCallReturnRef
(
std
::
move
(
value
)));
EXPECT_FALSE
(
CanCallReturnRef
(
value
+
1
));
EXPECT_FALSE
(
CanCallReturnRef
(
123
));
}
// Tests that ReturnRef(v) is not working with const temporaries (const T&&)
TEST
(
ReturnRefTest
,
WillNotAcceptConstTemporaryAkaContRValueRef
)
{
const
int
value
=
42
;
EXPECT_TRUE
(
CanCallReturnRef
(
value
));
EXPECT_FALSE
(
CanCallReturnRef
(
std
::
move
(
value
)));
}
// Tests that ReturnRefOfCopy(v) works for reference types.
// Tests that ReturnRefOfCopy(v) works for reference types.
TEST
(
ReturnRefOfCopyTest
,
WorksForReference
)
{
TEST
(
ReturnRefOfCopyTest
,
WorksForReference
)
{
int
n
=
42
;
int
n
=
42
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment