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
a198966d
Commit
a198966d
authored
Jan 29, 2011
by
vladlosev
Browse files
Renames some internal functions to avoid name clashes.
parent
48b13151
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
26 deletions
+34
-26
include/gtest/gtest-printers.h
include/gtest/gtest-printers.h
+6
-6
include/gtest/internal/gtest-port.h
include/gtest/internal/gtest-port.h
+19
-11
src/gtest-printers.cc
src/gtest-printers.cc
+2
-2
test/gtest-port_test.cc
test/gtest-port_test.cc
+7
-7
No files found.
include/gtest/gtest-printers.h
View file @
a198966d
...
...
@@ -404,22 +404,22 @@ GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
// Overloads for C strings.
GTEST_API_
void
PrintTo
(
const
char
*
s
,
::
std
::
ostream
*
os
);
inline
void
PrintTo
(
char
*
s
,
::
std
::
ostream
*
os
)
{
PrintTo
(
i
mplicit
_c
ast
<
const
char
*>
(
s
),
os
);
PrintTo
(
I
mplicit
C
ast
_
<
const
char
*>
(
s
),
os
);
}
// signed/unsigned char is often used for representing binary data, so
// we print pointers to it as void* to be safe.
inline
void
PrintTo
(
const
signed
char
*
s
,
::
std
::
ostream
*
os
)
{
PrintTo
(
i
mplicit
_c
ast
<
const
void
*>
(
s
),
os
);
PrintTo
(
I
mplicit
C
ast
_
<
const
void
*>
(
s
),
os
);
}
inline
void
PrintTo
(
signed
char
*
s
,
::
std
::
ostream
*
os
)
{
PrintTo
(
i
mplicit
_c
ast
<
const
void
*>
(
s
),
os
);
PrintTo
(
I
mplicit
C
ast
_
<
const
void
*>
(
s
),
os
);
}
inline
void
PrintTo
(
const
unsigned
char
*
s
,
::
std
::
ostream
*
os
)
{
PrintTo
(
i
mplicit
_c
ast
<
const
void
*>
(
s
),
os
);
PrintTo
(
I
mplicit
C
ast
_
<
const
void
*>
(
s
),
os
);
}
inline
void
PrintTo
(
unsigned
char
*
s
,
::
std
::
ostream
*
os
)
{
PrintTo
(
i
mplicit
_c
ast
<
const
void
*>
(
s
),
os
);
PrintTo
(
I
mplicit
C
ast
_
<
const
void
*>
(
s
),
os
);
}
// MSVC can be configured to define wchar_t as a typedef of unsigned
...
...
@@ -431,7 +431,7 @@ inline void PrintTo(unsigned char* s, ::std::ostream* os) {
// Overloads for wide C strings
GTEST_API_
void
PrintTo
(
const
wchar_t
*
s
,
::
std
::
ostream
*
os
);
inline
void
PrintTo
(
wchar_t
*
s
,
::
std
::
ostream
*
os
)
{
PrintTo
(
i
mplicit
_c
ast
<
const
wchar_t
*>
(
s
),
os
);
PrintTo
(
I
mplicit
C
ast
_
<
const
wchar_t
*>
(
s
),
os
);
}
#endif
...
...
include/gtest/internal/gtest-port.h
View file @
a198966d
...
...
@@ -919,25 +919,29 @@ inline void FlushInfoLog() { fflush(NULL); }
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// Use
i
mplicit
_c
ast as a safe version of static_cast for upcasting in
// Use
I
mplicit
C
ast
_
as a safe version of static_cast for upcasting in
// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
// const Foo*). When you use
i
mplicit
_c
ast, the compiler checks that
// the cast is safe. Such explicit
i
mplicit
_c
asts are necessary in
// const Foo*). When you use
I
mplicit
C
ast
_
, the compiler checks that
// the cast is safe. Such explicit
I
mplicit
C
ast
_
s are necessary in
// surprisingly many situations where C++ demands an exact type match
// instead of an argument type convertable to a target type.
//
// The syntax for using
i
mplicit
_c
ast is the same as for static_cast:
// The syntax for using
I
mplicit
C
ast
_
is the same as for static_cast:
//
//
i
mplicit
_c
ast<ToType>(expr)
//
I
mplicit
C
ast
_
<ToType>(expr)
//
//
i
mplicit
_c
ast would have been part of the C++ standard library,
//
I
mplicit
C
ast
_
would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make
// its way into the language in the future.
//
// This relatively ugly name is intentional. It prevents clashes with
// similar functions users may have (e.g., implicit_cast). The internal
// namespace alone is not enough because the function can be found by ADL.
template
<
typename
To
>
inline
To
i
mplicit
_c
ast
(
To
x
)
{
return
x
;
}
inline
To
I
mplicit
C
ast
_
(
To
x
)
{
return
x
;
}
// When you upcast (that is, cast a pointer from type Foo to type
// SuperclassOfFoo), it's fine to use
i
mplicit
_c
ast<>, since upcasts
// SuperclassOfFoo), it's fine to use
I
mplicit
C
ast
_
<>, since upcasts
// always succeed. When you downcast (that is, cast a pointer from
// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
// how do you know the pointer is really of type SubclassOfFoo? It
...
...
@@ -953,15 +957,19 @@ inline To implicit_cast(To x) { return x; }
// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
// You should design the code some other way not to need this.
template
<
typename
To
,
typename
From
>
// use like this: down_cast<T*>(foo);
inline
To
down_cast
(
From
*
f
)
{
// so we only accept pointers
//
// This relatively ugly name is intentional. It prevents clashes with
// similar functions users may have (e.g., down_cast). The internal
// namespace alone is not enough because the function can be found by ADL.
template
<
typename
To
,
typename
From
>
// use like this: DownCast_<T*>(foo);
inline
To
DownCast_
(
From
*
f
)
{
// so we only accept pointers
// Ensures that To is a sub-type of From *. This test is here only
// for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away
// completely.
if
(
false
)
{
const
To
to
=
NULL
;
::
testing
::
internal
::
i
mplicit
_c
ast
<
From
*>
(
to
);
::
testing
::
internal
::
I
mplicit
C
ast
_
<
From
*>
(
to
);
}
#if GTEST_HAS_RTTI
...
...
src/gtest-printers.cc
View file @
a198966d
...
...
@@ -308,7 +308,7 @@ void PrintTo(const char* s, ostream* os) {
if
(
s
==
NULL
)
{
*
os
<<
"NULL"
;
}
else
{
*
os
<<
i
mplicit
_c
ast
<
const
void
*>
(
s
)
<<
" pointing to "
;
*
os
<<
I
mplicit
C
ast
_
<
const
void
*>
(
s
)
<<
" pointing to "
;
PrintCharsAsStringTo
(
s
,
strlen
(
s
),
os
);
}
}
...
...
@@ -325,7 +325,7 @@ void PrintTo(const wchar_t* s, ostream* os) {
if
(
s
==
NULL
)
{
*
os
<<
"NULL"
;
}
else
{
*
os
<<
i
mplicit
_c
ast
<
const
void
*>
(
s
)
<<
" pointing to "
;
*
os
<<
I
mplicit
C
ast
_
<
const
void
*>
(
s
)
<<
" pointing to "
;
PrintWideCharsAsStringTo
(
s
,
wcslen
(
s
),
os
);
}
}
...
...
test/gtest-port_test.cc
View file @
a198966d
...
...
@@ -79,12 +79,12 @@ class Derived : public Base {
TEST
(
ImplicitCastTest
,
ConvertsPointers
)
{
Derived
derived
(
0
);
EXPECT_TRUE
(
&
derived
==
::
testing
::
internal
::
i
mplicit
_c
ast
<
Base
*>
(
&
derived
));
EXPECT_TRUE
(
&
derived
==
::
testing
::
internal
::
I
mplicit
C
ast
_
<
Base
*>
(
&
derived
));
}
TEST
(
ImplicitCastTest
,
CanUseInheritance
)
{
Derived
derived
(
1
);
Base
base
=
::
testing
::
internal
::
i
mplicit
_c
ast
<
Base
>
(
derived
);
Base
base
=
::
testing
::
internal
::
I
mplicit
C
ast
_
<
Base
>
(
derived
);
EXPECT_EQ
(
derived
.
member
(),
base
.
member
());
}
...
...
@@ -103,7 +103,7 @@ class Castable {
TEST
(
ImplicitCastTest
,
CanUseNonConstCastOperator
)
{
bool
converted
=
false
;
Castable
castable
(
&
converted
);
Base
base
=
::
testing
::
internal
::
i
mplicit
_c
ast
<
Base
>
(
castable
);
Base
base
=
::
testing
::
internal
::
I
mplicit
C
ast
_
<
Base
>
(
castable
);
EXPECT_TRUE
(
converted
);
}
...
...
@@ -122,7 +122,7 @@ class ConstCastable {
TEST
(
ImplicitCastTest
,
CanUseConstCastOperatorOnConstValues
)
{
bool
converted
=
false
;
const
ConstCastable
const_castable
(
&
converted
);
Base
base
=
::
testing
::
internal
::
i
mplicit
_c
ast
<
Base
>
(
const_castable
);
Base
base
=
::
testing
::
internal
::
I
mplicit
C
ast
_
<
Base
>
(
const_castable
);
EXPECT_TRUE
(
converted
);
}
...
...
@@ -148,14 +148,14 @@ TEST(ImplicitCastTest, CanSelectBetweenConstAndNonConstCasrAppropriately) {
bool
converted
=
false
;
bool
const_converted
=
false
;
ConstAndNonConstCastable
castable
(
&
converted
,
&
const_converted
);
Base
base
=
::
testing
::
internal
::
i
mplicit
_c
ast
<
Base
>
(
castable
);
Base
base
=
::
testing
::
internal
::
I
mplicit
C
ast
_
<
Base
>
(
castable
);
EXPECT_TRUE
(
converted
);
EXPECT_FALSE
(
const_converted
);
converted
=
false
;
const_converted
=
false
;
const
ConstAndNonConstCastable
const_castable
(
&
converted
,
&
const_converted
);
base
=
::
testing
::
internal
::
i
mplicit
_c
ast
<
Base
>
(
const_castable
);
base
=
::
testing
::
internal
::
I
mplicit
C
ast
_
<
Base
>
(
const_castable
);
EXPECT_FALSE
(
converted
);
EXPECT_TRUE
(
const_converted
);
}
...
...
@@ -167,7 +167,7 @@ class To {
TEST
(
ImplicitCastTest
,
CanUseImplicitConstructor
)
{
bool
converted
=
false
;
To
to
=
::
testing
::
internal
::
i
mplicit
_c
ast
<
To
>
(
&
converted
);
To
to
=
::
testing
::
internal
::
I
mplicit
C
ast
_
<
To
>
(
&
converted
);
(
void
)
to
;
EXPECT_TRUE
(
converted
);
}
...
...
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