No appropriate default constructor available within googletest EXPECT_NO_THROW
c++, googletest
Solution
This is a bug in gtest I think (although I'm no expert on macros). `EXPECT_NO_THROW` ultimately expands to:
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { statement; }
Your code compiles using VS2012RC if `statement` is wrapped in parentheses in the `if` body:
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { (statement); }
// ^ ^
As a workaround, you can do:
EXPECT_NO_THROW ((ClassOne (classThree)));
Problem
Declaration: ``` class ClassOne { ClassOne (ClassTwo* classTwo, ClassThree const& classThree); } ``` Test: ``` ClassTwo* classTwo; ClassThree classThree; EXPECT_NO_THROW (ClassOne (classTwo, classThree)); ``` This compiles and runs, but now I change it to: Declaration: ``` class ClassOne { ClassOne (ClassThree const& classThree); } ``` Test: ``` ClassThree classThree; EXPECT_NO_THROW (ClassOne (classThree)); ``` This fails with "no appropriate default constructor available". The following lines compile: ``` ClassOne classOne (classTwo, classThree); // First case ClassOne classOne (classThree); // Second case ``` Is there some reason why I can't `EXPECT_NO_THROW` on a constructor with one parameter?