This is because it BOOST_CHECK_THROWis a macro and Foo(bar)extends to an operator. The compiler sees this statement and interprets it as a variable declaration Foo bar;, which requires a default constructor.
, :
BOOST_CHECK_THROW( Foo temp( bar ), std::logic_error );
BOOST_CHECK_THROW -
try
{
Foo(bar);
}
catch( std::logic_error )
{
}
Foo(bar); bar. :
struct Test
{
Test(int *x) {}
};
int main()
{
int *x=0;
Test(x);
return 0;
}
g++
test.cpp: In function βint main()β:
test.cpp:10: error: conflicting declaration βTest xβ
test.cpp:9: error: βxβ has a previous declaration as βint* xβ