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

CHECK_THROWS_AS of non-default constructor wants to call default constructor #293

Closed
mika-fischer opened this issue Sep 12, 2019 · 4 comments

Comments

@mika-fischer
Copy link

Description

Steps to reproduce

#include <doctest.h>
#include <exception>

struct foo {
    foo() = delete;
    foo(int);
    int bar();
};

TEST_CASE("foo") {
    int i = 0;
    SUBCASE("empty") {
        CHECK_THROWS_AS(foo(i), std::exception); // error: use of deleted function 'foo::foo()'
    }
    SUBCASE("bar") {
        CHECK_THROWS_AS(foo(i).bar(), std::exception); // works
    }
    SUBCASE("empty") {
        CHECK_THROWS_AS(foo(int(i)), std::exception); // works
    }
}

See https://godbolt.org/z/7t32D-

Extra information

  • doctest version: v2.3.4
@onqtam
Copy link
Member

onqtam commented Sep 12, 2019

Try using DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
It works with it:
https://godbolt.org/z/XKcaTm

@onqtam
Copy link
Member

onqtam commented Sep 19, 2019

Did that help?

Btw even without doctest you would get an error if you just wrote foo(i); in function scope, but if you cast it to void like this: (void)foo(i); it works. I'm thinking of closing this issue...

@mika-fischer
Copy link
Author

Sorry, I forgot about this. I rolled back the conversion from catch2 to doctest because of the missung GENERATE feature, so I didn't get around to testing this...

But the suggested fix works, thanks. Maybe this should be the default?

@onqtam
Copy link
Member

onqtam commented Sep 19, 2019

I've forgotten why it isn't the default - either because it was a breaking change or because of something else (like some other kind of expression not being castable to void or something...).

How much are you using the generators? Can the code be emulated with some loop of some sorts?

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