From 7c4164bf404d899b6d4c74beb1070da5647f55a2 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 18 Jan 2019 14:53:25 +0300 Subject: [PATCH] Fix INSTANTIATE_TEST_CASE_P with zero variadic arguments --- googletest/include/gtest/gtest-param-test.h | 14 +++++------ .../include/gtest/internal/gtest-param-util.h | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index a0eecc69..81b1a4bc 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -544,9 +544,9 @@ internal::CartesianProductHolder10, and return std::string. // // testing::PrintToStringParamName is a builtin test suffix generator that @@ -556,15 +556,15 @@ internal::CartesianProductHolder10 \ gtest_##prefix##test_suite_name##_EvalGenerator_() { \ - return generator; \ + return VA_GETFIRST(__VA_ARGS__); \ } \ static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \ const ::testing::TestParamInfo& info) { \ - return ::testing::internal::GetParamNameGen( \ - __VA_ARGS__)(info); \ + return ::testing::internal::CreateParamGenerator< \ + test_suite_name::ParamType>(VA_GETREST(__VA_ARGS__, 0))(info); \ } \ static int gtest_##prefix##test_suite_name##_dummy_ \ GTEST_ATTRIBUTE_UNUSED_ = \ diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index bca72539..e0592222 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -396,6 +397,30 @@ typename ParamNameGenFunc::Type *GetParamNameGen() { return DefaultParamName; } +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Macroses allow to address an issue with zero element variadic macro + +#define EXPAND(X) X +#define VA__GETFIRST(X, ...) X +#define VA_GETFIRST(...) EXPAND(VA__GETFIRST(__VA_ARGS__, 0)) +#define VA_GETREST(X, ...) __VA_ARGS__ + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Function is intended to swallow 0 as last argument and call GetParamNameGen + +template +auto CreateParamGenerator(int) -> decltype(GetParamNameGen()) { + return GetParamNameGen(); +} + +template +auto CreateParamGenerator(Arg&& arg, int) -> decltype( + GetParamNameGen(std::forward(arg))) { + return GetParamNameGen(std::forward(arg)); +} + // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // // Stores a parameter value and later creates tests parameterized with that