Googletest export

Merge 3bdefdb473d304803d2a38e2a2cd5cdc1827c3bd into fb49e6c164

Closes #2407

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/googletest/pull/2407 from kuzkry:StaticAssertTypeEq 3bdefdb473d304803d2a38e2a2cd5cdc1827c3bd
PiperOrigin-RevId: 269255328
This commit is contained in:
kuzkry
2019-09-16 01:46:55 -04:00
committed by Shaindel Schwartz
parent cad3bc46c2
commit f2fb48c3b3
7 changed files with 26 additions and 38 deletions

View File

@@ -464,9 +464,10 @@ You can call the function
to assert that types `T1` and `T2` are the same. The function does nothing if
the assertion is satisfied. If the types are different, the function call will
fail to compile, and the compiler error message will likely (depending on the
compiler) show you the actual values of `T1` and `T2`. This is mainly useful
inside template code.
fail to compile, the compiler error message will say that
`type1 and type2 are not the same type` and most likely (depending on the compiler)
show you the actual values of `T1` and `T2`. This is mainly useful inside
template code.
**Caveat**: When used inside a member function of a class template or a function
template, `StaticAssertTypeEq<T1, T2>()` is effective only if the function is

View File

@@ -2297,8 +2297,9 @@ class GTEST_API_ ScopedTrace {
//
// to cause a compiler error.
template <typename T1, typename T2>
bool StaticAssertTypeEq() {
(void)internal::StaticAssertTypeEqHelper<T1, T2>();
constexpr bool StaticAssertTypeEq() noexcept {
static_assert(std::is_same<T1, T2>::value,
"type1 and type2 are not the same type");
return true;
}

View File

@@ -1069,10 +1069,9 @@ class NativeArray {
}
private:
enum {
kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper<
Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value
};
static_assert(!std::is_const<Element>::value, "Type must not be const");
static_assert(!std::is_reference<Element>::value,
"Type must not be a reference");
// Initializes this object with a copy of the input.
void InitCopy(const Element* array, size_t a_size) {

View File

@@ -856,17 +856,6 @@ class Secret;
// expression is false, compiler will issue an error containing this identifier.
#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg)
// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
//
// This template is declared, but intentionally undefined.
template <typename T1, typename T2>
struct StaticAssertTypeEqHelper;
template <typename T>
struct StaticAssertTypeEqHelper<T, T> {
enum { value = true };
};
// Evaluates to the number of elements in 'array'.
#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0]))