|
Boost Users : |
Subject: [Boost-users] [Boost][Test] Compile error with BOOST_REQUIRE_THROW
From: Martin Desharnais (martin.desharnais_at_[hidden])
Date: 2011-08-26 20:48:05
Hi,
I've just found that we have a compiler error when using the
BOOST_REQUIRE_THROW macro in a if/else statement with implicit block.
Let's have an example:
BOOST_AUTO_TEST_CASE(foo)
{
if(true)
BOOST_REQUIRE_THROW(throw std::exception(), std::exception);
else
BOOST_REQUIRE_THROW(throw std::exception(), std::exception);
}
Will fail with:
file.cpp: In member function âvoid foo::test_method()â:
file.cpp:184:2: error: âelseâ without a previous âifâ
To make it work, we need to put explicit block:
BOOST_AUTO_TEST_CASE(foo)
{
if(true)
{
BOOST_REQUIRE_THROW(throw std::exception(), std::exception);
}
else
{
BOOST_REQUIRE_THROW(throw std::exception(), std::exception);
}
}
Wouldn't it be possible to add this block in the macro so library users
don't have to care about?
PS: Sorry for my writing, I'm not a native English speaker.
-- Martin Desharnais martin.desharnais_at_[hidden]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net