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
f31bf1d3
Commit
f31bf1d3
authored
Jan 08, 2019
by
misterg
Committed by
gennadiycivil
Jan 08, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Replace testing::internal::ImplicitlyConvertible with std::is_convertible Fixes #2054 PiperOrigin-RevId: 228334305
parent
216c37f0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
87 deletions
+9
-87
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+4
-4
gtest-printers.h
googletest/include/gtest/gtest-printers.h
+2
-2
gtest.h
googletest/include/gtest/gtest.h
+1
-1
gtest-internal.h
googletest/include/gtest/internal/gtest-internal.h
+2
-50
gtest_unittest.cc
googletest/test/gtest_unittest.cc
+0
-30
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
f31bf1d3
...
...
@@ -128,9 +128,9 @@ class MatcherCastImpl {
return
CastImpl
(
polymorphic_matcher_or_value
,
BooleanConstant
<
internal
::
ImplicitlyC
onvertible
<
M
,
Matcher
<
T
>
>::
value
>
(),
std
::
is_c
onvertible
<
M
,
Matcher
<
T
>
>::
value
>
(),
BooleanConstant
<
internal
::
ImplicitlyC
onvertible
<
M
,
T
>::
value
>
());
std
::
is_c
onvertible
<
M
,
T
>::
value
>
());
}
private
:
...
...
@@ -268,8 +268,8 @@ class SafeMatcherCastImpl {
template
<
typename
U
>
static
inline
Matcher
<
T
>
Cast
(
const
Matcher
<
U
>&
matcher
)
{
// Enforce that T can be implicitly converted to U.
GTEST_COMPILE_ASSERT_
((
internal
::
ImplicitlyC
onvertible
<
T
,
U
>::
value
),
T_must_be_implicitly_convertible_to_U
);
GTEST_COMPILE_ASSERT_
((
std
::
is_c
onvertible
<
T
,
U
>::
value
),
"T must be implicitly convertible to U"
);
// Enforce that we are not converting a non-reference type T to a reference
// type U.
GTEST_COMPILE_ASSERT_
(
...
...
googletest/include/gtest/gtest-printers.h
View file @
f31bf1d3
...
...
@@ -232,12 +232,12 @@ template <typename Char, typename CharTraits, typename T>
::
std
::
basic_ostream
<
Char
,
CharTraits
>&
os
,
const
T
&
x
)
{
TypeWithoutFormatter
<
T
,
(
internal
::
IsAProtocolMessage
<
T
>::
value
?
kProtobuf
:
internal
::
ImplicitlyC
onvertible
<
:
std
::
is_c
onvertible
<
const
T
&
,
internal
::
BiggestInt
>::
value
?
kConvertibleToInteger
:
#if GTEST_HAS_ABSL
internal
::
ImplicitlyC
onvertible
<
std
::
is_c
onvertible
<
const
T
&
,
absl
::
string_view
>::
value
?
kConvertibleToStringView
:
...
...
googletest/include/gtest/gtest.h
View file @
f31bf1d3
...
...
@@ -306,7 +306,7 @@ class GTEST_API_ AssertionResult {
explicit
AssertionResult
(
const
T
&
success
,
typename
internal
::
EnableIf
<
!
internal
::
ImplicitlyC
onvertible
<
T
,
AssertionResult
>::
value
>::
type
*
!
std
::
is_c
onvertible
<
T
,
AssertionResult
>::
value
>::
type
*
/*enabler*/
=
nullptr
)
:
success_
(
success
)
{}
...
...
googletest/include/gtest/internal/gtest-internal.h
View file @
f31bf1d3
...
...
@@ -920,62 +920,14 @@ struct RemoveConst<const T[N]> {
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
// ImplicitlyConvertible<From, To>::value is a compile-time bool
// constant that's true iff type From can be implicitly converted to
// type To.
template
<
typename
From
,
typename
To
>
class
ImplicitlyConvertible
{
private
:
// We need the following helper functions only for their types.
// They have no implementations.
// MakeFrom() is an expression whose type is From. We cannot simply
// use From(), as the type From may not have a public default
// constructor.
static
typename
AddReference
<
From
>::
type
MakeFrom
();
// These two functions are overloaded. Given an expression
// Helper(x), the compiler will pick the first version if x can be
// implicitly converted to type To; otherwise it will pick the
// second version.
//
// The first version returns a value of size 1, and the second
// version returns a value of size 2. Therefore, by checking the
// size of Helper(x), which can be done at compile time, we can tell
// which version of Helper() is used, and hence whether x can be
// implicitly converted to type To.
static
char
Helper
(
To
);
static
char
(
&
Helper
(...))[
2
];
// NOLINT
// We have to put the 'public' section after the 'private' section,
// or MSVC refuses to compile the code.
public
:
#if defined(__BORLANDC__)
// C++Builder cannot use member overload resolution during template
// instantiation. The simplest workaround is to use its C++0x type traits
// functions (C++Builder 2009 and above only).
static
const
bool
value
=
__is_convertible
(
From
,
To
);
#else
// MSVC warns about implicitly converting from double to int for
// possible loss of data, so we need to temporarily disable the
// warning.
GTEST_DISABLE_MSC_WARNINGS_PUSH_
(
4244
)
static
const
bool
value
=
sizeof
(
Helper
(
ImplicitlyConvertible
::
MakeFrom
()))
==
1
;
GTEST_DISABLE_MSC_WARNINGS_POP_
()
#endif // __BORLANDC__
};
template
<
typename
From
,
typename
To
>
const
bool
ImplicitlyConvertible
<
From
,
To
>::
value
;
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
// true iff T is type ProtocolMessage, proto2::Message, or a subclass
// of those.
template
<
typename
T
>
struct
IsAProtocolMessage
:
public
bool_constant
<
ImplicitlyC
onvertible
<
const
T
*
,
const
::
ProtocolMessage
*>::
value
||
ImplicitlyC
onvertible
<
const
T
*
,
const
::
proto2
::
Message
*>::
value
>
{
std
::
is_c
onvertible
<
const
T
*
,
const
::
ProtocolMessage
*>::
value
||
std
::
is_c
onvertible
<
const
T
*
,
const
::
proto2
::
Message
*>::
value
>
{
};
// When the compiler sees expression IsContainerTest<C>(0), if C is an
...
...
googletest/test/gtest_unittest.cc
View file @
f31bf1d3
...
...
@@ -250,7 +250,6 @@ using testing::internal::GetTestTypeId;
using
testing
::
internal
::
GetTimeInMillis
;
using
testing
::
internal
::
GetTypeId
;
using
testing
::
internal
::
GetUnitTestImpl
;
using
testing
::
internal
::
ImplicitlyConvertible
;
using
testing
::
internal
::
Int32
;
using
testing
::
internal
::
Int32FromEnvOrDie
;
using
testing
::
internal
::
IsAProtocolMessage
;
...
...
@@ -7240,35 +7239,6 @@ TEST(GTestReferenceToConstTest, Works) {
TestGTestReferenceToConst
<
const
std
::
string
&
,
const
std
::
string
&>
();
}
// Tests that ImplicitlyConvertible<T1, T2>::value is a compile-time constant.
TEST
(
ImplicitlyConvertibleTest
,
ValueIsCompileTimeConstant
)
{
GTEST_COMPILE_ASSERT_
((
ImplicitlyConvertible
<
int
,
int
>::
value
),
const_true
);
GTEST_COMPILE_ASSERT_
((
!
ImplicitlyConvertible
<
void
*
,
int
*>::
value
),
const_false
);
}
// Tests that ImplicitlyConvertible<T1, T2>::value is true when T1 can
// be implicitly converted to T2.
TEST
(
ImplicitlyConvertibleTest
,
ValueIsTrueWhenConvertible
)
{
EXPECT_TRUE
((
ImplicitlyConvertible
<
int
,
double
>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
double
,
int
>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
int
*
,
void
*>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
int
*
,
const
int
*>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
ConversionHelperDerived
&
,
const
ConversionHelperBase
&>::
value
));
EXPECT_TRUE
((
ImplicitlyConvertible
<
const
ConversionHelperBase
,
ConversionHelperBase
>::
value
));
}
// Tests that ImplicitlyConvertible<T1, T2>::value is false when T1
// cannot be implicitly converted to T2.
TEST
(
ImplicitlyConvertibleTest
,
ValueIsFalseWhenNotConvertible
)
{
EXPECT_FALSE
((
ImplicitlyConvertible
<
double
,
int
*>::
value
));
EXPECT_FALSE
((
ImplicitlyConvertible
<
void
*
,
int
*>::
value
));
EXPECT_FALSE
((
ImplicitlyConvertible
<
const
int
*
,
int
*>::
value
));
EXPECT_FALSE
((
ImplicitlyConvertible
<
ConversionHelperBase
&
,
ConversionHelperDerived
&>::
value
));
}
// Tests IsContainerTest.
...
...
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