Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
db13ff1f
Commit
db13ff1f
authored
Nov 26, 2019
by
Gennadiy Rozental
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2597 from kuzkry:remove-workaround_Nokia-Sybian-SafeMatcherCastImpl
PiperOrigin-RevId: 282581402
parents
be74b4b2
bbbc5d8a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
32 deletions
+19
-32
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+19
-32
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
db13ff1f
...
@@ -247,31 +247,24 @@ inline Matcher<T> MatcherCast(const M& matcher) {
...
@@ -247,31 +247,24 @@ inline Matcher<T> MatcherCast(const M& matcher) {
return
internal
::
MatcherCastImpl
<
T
,
M
>::
Cast
(
matcher
);
return
internal
::
MatcherCastImpl
<
T
,
M
>::
Cast
(
matcher
);
}
}
// Implements SafeMatcherCast().
// This overload handles polymorphic matchers and values only since
//
// monomorphic matchers are handled by the next one.
// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
template
<
typename
T
,
typename
M
>
// workaround for a compiler bug, and can now be removed.
inline
Matcher
<
T
>
SafeMatcherCast
(
const
M
&
polymorphic_matcher_or_value
)
{
template
<
typename
T
>
return
MatcherCast
<
T
>
(
polymorphic_matcher_or_value
);
class
SafeMatcherCastImpl
{
}
public
:
// This overload handles polymorphic matchers and values only since
// monomorphic matchers are handled by the next one.
template
<
typename
M
>
static
inline
Matcher
<
T
>
Cast
(
const
M
&
polymorphic_matcher_or_value
)
{
return
internal
::
MatcherCastImpl
<
T
,
M
>::
Cast
(
polymorphic_matcher_or_value
);
}
// This overload handles monomorphic matchers.
// This overload handles monomorphic matchers.
//
//
// In general, if type T can be implicitly converted to type U, we can
// In general, if type T can be implicitly converted to type U, we can
// safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
// safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
// contravariant): just keep a copy of the original Matcher<U>, convert the
// contravariant): just keep a copy of the original Matcher<U>, convert the
// argument from type T to U, and then pass it to the underlying Matcher<U>.
// argument from type T to U, and then pass it to the underlying Matcher<U>.
// The only exception is when U is a reference and T is not, as the
// The only exception is when U is a reference and T is not, as the
// underlying Matcher<U> may be interested in the argument's address, which
// underlying Matcher<U> may be interested in the argument's address, which
// is not preserved in the conversion from T to U.
// is not preserved in the conversion from T to U.
template
<
typename
U
>
template
<
typename
T
,
typename
U
>
static
inline
Matcher
<
T
>
Cast
(
const
Matcher
<
U
>&
matcher
)
{
inline
Matcher
<
T
>
SafeMatcher
Cast
(
const
Matcher
<
U
>&
matcher
)
{
// Enforce that T can be implicitly converted to U.
// Enforce that T can be implicitly converted to U.
GTEST_COMPILE_ASSERT_
((
std
::
is_convertible
<
T
,
U
>::
value
),
GTEST_COMPILE_ASSERT_
((
std
::
is_convertible
<
T
,
U
>::
value
),
"T must be implicitly convertible to U"
);
"T must be implicitly convertible to U"
);
...
@@ -284,19 +277,13 @@ class SafeMatcherCastImpl {
...
@@ -284,19 +277,13 @@ class SafeMatcherCastImpl {
// conversion is not lossy.
// conversion is not lossy.
typedef
GTEST_REMOVE_REFERENCE_AND_CONST_
(
T
)
RawT
;
typedef
GTEST_REMOVE_REFERENCE_AND_CONST_
(
T
)
RawT
;
typedef
GTEST_REMOVE_REFERENCE_AND_CONST_
(
U
)
RawU
;
typedef
GTEST_REMOVE_REFERENCE_AND_CONST_
(
U
)
RawU
;
const
bool
kTIsOther
=
GMOCK_KIND_OF_
(
RawT
)
==
internal
::
kOther
;
constexpr
bool
kTIsOther
=
GMOCK_KIND_OF_
(
RawT
)
==
internal
::
kOther
;
const
bool
kUIsOther
=
GMOCK_KIND_OF_
(
RawU
)
==
internal
::
kOther
;
constexpr
bool
kUIsOther
=
GMOCK_KIND_OF_
(
RawU
)
==
internal
::
kOther
;
GTEST_COMPILE_ASSERT_
(
GTEST_COMPILE_ASSERT_
(
kTIsOther
||
kUIsOther
||
kTIsOther
||
kUIsOther
||
(
internal
::
LosslessArithmeticConvertible
<
RawT
,
RawU
>::
value
),
(
internal
::
LosslessArithmeticConvertible
<
RawT
,
RawU
>::
value
),
conversion_of_arithmetic_types_must_be_lossless
);
conversion_of_arithmetic_types_must_be_lossless
);
return
MatcherCast
<
T
>
(
matcher
);
return
MatcherCast
<
T
>
(
matcher
);
}
};
template
<
typename
T
,
typename
M
>
inline
Matcher
<
T
>
SafeMatcherCast
(
const
M
&
polymorphic_matcher
)
{
return
SafeMatcherCastImpl
<
T
>::
Cast
(
polymorphic_matcher
);
}
}
// A<T>() returns a matcher that matches any value of type T.
// A<T>() returns a matcher that matches any value of type T.
...
...
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