googletest and EXPECT_THROW weirdness

Posted by thumper on Stack Overflow See other posts from Stack Overflow or by thumper
Published on 2011-06-22T23:07:57Z Indexed on 2011/06/23 0:23 UTC
Read the original article Hit count: 407

Filed under:
|
|

I have a class that has no default constructor, but the construct may throw.

I was wanting to have a test like:

EXPECT_THROW(MyClass(param), std::runtime_error);

But the compiler, g++, complains that there is no default constructor for Myclass.

However the following:

EXPECT_THROW(MyClass foo(param), std::runtime_error);

Works, and the test passes as expected. Why though won't googletest accept the temporary object?

© Stack Overflow or respective owner

Related posts about c++

Related posts about g++