diff options
author | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-01-08 01:10:31 +0000 |
---|---|---|
committer | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-01-08 01:10:31 +0000 |
commit | 53e0dc4041f660b6517b15b08b496e164be614f1 (patch) | |
tree | fc8832cf39d3e67358299901d7474fb9a7b2dfe4 /include/gtest/gtest.h | |
parent | 0efb17dc540ff5fbc9bf2ca370e42347d4d3a6d9 (diff) | |
download | googletest-53e0dc4041f660b6517b15b08b496e164be614f1.tar.gz googletest-53e0dc4041f660b6517b15b08b496e164be614f1.tar.bz2 googletest-53e0dc4041f660b6517b15b08b496e164be614f1.zip |
Implements the --gtest_death_test_use_fork flag and StaticAssertTypeEq.
Diffstat (limited to 'include/gtest/gtest.h')
-rw-r--r-- | include/gtest/gtest.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index ebd3123b..dfa338b2 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -1242,6 +1242,52 @@ AssertionResult DoubleLE(const char* expr1, const char* expr2, ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\ __FILE__, __LINE__, ::testing::Message() << (message)) +namespace internal { + +// This template is declared, but intentionally undefined. +template <typename T1, typename T2> +struct StaticAssertTypeEqHelper; + +template <typename T> +struct StaticAssertTypeEqHelper<T, T> {}; + +} // namespace internal + +// Compile-time assertion for type equality. +// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are +// the same type. The value it returns is not interesting. +// +// Instead of making StaticAssertTypeEq a class template, we make it a +// function template that invokes a helper class template. This +// prevents a user from misusing StaticAssertTypeEq<T1, T2> by +// defining objects of that type. +// +// CAVEAT: +// +// When used inside a method of a class template, +// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is +// instantiated. For example, given: +// +// template <typename T> class Foo { +// public: +// void Bar() { testing::StaticAssertTypeEq<int, T>(); } +// }; +// +// the code: +// +// void Test1() { Foo<bool> foo; } +// +// will NOT generate a compiler error, as Foo<bool>::Bar() is never +// actually instantiated. Instead, you need: +// +// void Test2() { Foo<bool> foo; foo.Bar(); } +// +// to cause a compiler error. +template <typename T1, typename T2> +bool StaticAssertTypeEq() { + internal::StaticAssertTypeEqHelper<T1, T2>(); + return true; +} // Defines a test. // |