From 78b4e9b8bb6374ab669e4c44433dbf71b508b8cb Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Wed, 30 Jun 2021 13:40:15 +0200 Subject: [PATCH] Allow empty Type<> type list --- googletest/include/gtest/internal/gtest-type-util.h | 13 ++++++++++++- googletest/test/gtest-typed-test_test.cc | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-type-util.h b/googletest/include/gtest/internal/gtest-type-util.h index b87a2e2c..59c8582b 100644 --- a/googletest/include/gtest/internal/gtest-type-util.h +++ b/googletest/include/gtest/internal/gtest-type-util.h @@ -147,11 +147,22 @@ struct Types { using Tail = None; }; +// Helper metafunction to convert an empty ::testing::Types list to None +template +struct types_or_none { + using type = Types; +}; + +template <> +struct types_or_none<> { + using type = None; +}; + // Helper metafunctions to tell apart a single type from types // generated by ::testing::Types template struct ProxyTypeList { - using type = Types; + using type = typename types_or_none::type; }; template diff --git a/googletest/test/gtest-typed-test_test.cc b/googletest/test/gtest-typed-test_test.cc index 5fc678cb..35f3cc0c 100644 --- a/googletest/test/gtest-typed-test_test.cc +++ b/googletest/test/gtest-typed-test_test.cc @@ -150,6 +150,19 @@ TYPED_TEST_SUITE(TypedTest2, Types); // share the same name. TYPED_TEST(TypedTest2, A) {} +template +class TypedTest3 : public Test { +}; + +// Verifies that an empty Types<> type list works. +// This is useful in case Types<> is constructed conditionally, e.g. +// `my_types = typename std::conditional>::type;` +TYPED_TEST_SUITE(TypedTest3, Types<>); + +TYPED_TEST(TypedTest3, A) { + ASSERT_TRUE(false); // Make sure this test is never executed. +} + // Tests that a typed test case can be defined in a namespace. namespace library1 {