catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.6k stars 3.05k forks source link

Unable to use TEMPLATE_TEST_CASE_SIG with variadic template arguments #2289

Open gouletr opened 3 years ago

gouletr commented 3 years ago

Describe the bug

I've been trying to use TEMPLATE_TEST_CASE_SIG with variadic template parameters, just as mentioned in the documentation, but I've never been able to make it work. Suppose the following code:

template <class T, class... Args>
class Foo
{
public:
    bool Make(Args&&... args)
    {
        return true;
    }
};

TEMPLATE_TEST_CASE_SIG("test", "[test]", ((typename T, typename...Ts), T, Ts...), int, (int, true))
{
    auto foo = Foo<T>();
    REQUIRE(foo.Make(Ts...));
}

Compiler output the following error:

2>D:\Tests.cpp(98,1): error C2668: '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper': ambiguous call to overloaded function
2>D:\Tests.cpp(98,1): message : could be '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::Nttp<int> `anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper<int,>(void) noexcept'
2>D:\Tests.cpp(98,1): message : or       '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::TypeList<int> `anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper<int>(void) noexcept'
2>D:\Tests.cpp(98,1): message : while trying to match the argument list '()'
2>D:\Tests.cpp(98,1): error C2672: 'get_wrapper': no matching overloaded function found
2>D:\Tests.cpp(98,1): error C2974: '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper': invalid template argument for 'Cs', type expected
2>D:\Tests.cpp(98): message : see declaration of '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper'
2>D:\Tests.cpp(98,1): error C2974: '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper': invalid template argument for 'Ts', type expected
2>D:\Tests.cpp(98): message : see declaration of '`anonymous-namespace'::ns_____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____16::get_wrapper'

Expected behavior

Once the compile issue resolved, expecting the test case to be called with T = int then again with T = int, Ts = true.

Reproduction steps

Try compiling the code snippet above.

Platform information:

Additional context

Am I understanding correctly what TEMPLATE_TEST_CASE_SIG with variadic template parameters is able to do? Also tried to call the macro this way:

TEMPLATE_TEST_CASE_SIG("test", "[test]", ((typename T, typename...Ts), T, Ts...), (int, false), (int, true))

...but it results in the same error.

Dragoniko55 commented 2 years ago

I'm also getting this issue, but in my case I'm not even using variadic template parameters.

Simple example: https://godbolt.org/z/6nEsnfedh