Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Error with CHECK_NOTHROW when using 2 Template Arguments #372

Closed
phil-zxx opened this issue May 15, 2020 · 2 comments
Closed

Compile Error with CHECK_NOTHROW when using 2 Template Arguments #372

phil-zxx opened this issue May 15, 2020 · 2 comments

Comments

@phil-zxx
Copy link

Let's consider the following sample script:

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

template<class A, class B>
struct TestClass
{
    TestClass(int v) : value(v) { }
    int value;
};

using TestClassIntFloat = TestClass<int, float>;

TEST_CASE("SomeUnitTest")
{
    CHECK(TestClass<int, float>(5).value == 5);
    // CHECK_NOTHROW(TestClass<int, float>(5));  // <-- Does not compile

    CHECK(TestClassIntFloat(5).value == 5);
    CHECK_NOTHROW(TestClassIntFloat(5));  // <-- Compiles just fine
}

Line CHECK_NOTHROW(TestClass<int, float>(5)); does not compile. However, if I simply wrap the type via using TestClassIntFloat = TestClass<int, float>; then CHECK_NOTHROW(TestClassIntFloat(5)); compiles just fine. Same issue for CHECK_THROWS.

I am using doctest 2.3.7 and the error occurs on both MSVC 2019 and g++ 10:

  • MSVC: warning C4002: too many arguments for function-like macro invocation 'DOCTEST_CHECK_THROWS'
  • g++: error: macro "DOCTEST_CHECK_THROWS" passed 2 arguments, but takes just 1

This came up as I was trying to migrate from catch2 to doctest. When reverting back to catch by using these two lines

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

everything compiles, as expected.


I had a look at the code and i think changing this line

#define CHECK_THROWS DOCTEST_CHECK_THROWS

to

#define CHECK_THROWS(...) DOCTEST_CHECK_THROWS((__VA_ARGS__))

resolves the issue. But I am not sure if this has any other repercussions?

onqtam added a commit that referenced this issue May 17, 2020
… ==> allows for expressions with commas such as 'CHECK_NOTHROW(TestClass<int, float>(5));'
@onqtam
Copy link
Member

onqtam commented May 17, 2020

fixed in the dev branch!

@phil-zxx
Copy link
Author

Great, thanks a lot!

@onqtam onqtam closed this as completed May 17, 2020
onqtam added a commit that referenced this issue May 17, 2020
… ==> allows for expressions with commas such as 'CHECK_NOTHROW(TestClass<int, float>(5));'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants