Boost logo

Boost :

Subject: [boost] [Test] Small issue with explicit function initialization
From: Sylvain Bougerel (sylvain.bougerel.devel_at_[hidden])
Date: 2010-03-07 12:08:47


Hi,

I'm not sure if it's an issue or not. But I noticed that the given
code does not compile:

#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>

template <typename Tp1, typename Tp2>
inline Tp2
stupid_cast (const Tp1& arg) { return static_cast<Tp2>(arg); }

BOOST_AUTO_TEST_CASE( test_details_key )
{
  BOOST_CHECK(stupid_cast<float, int>(1.0) == 1);
}

It give the following error with g++ (GCC) 4.4.3:
try.cpp:40:48: error: macro "BOOST_CHECK" passed 2 arguments, but takes just 1
try.cpp: In member function 'void test_details_key::test_method()':
try.cpp:40: error: 'BOOST_CHECK' was not declared in this scope

While the following does compile (and runs well):

#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>

template <typename Tp1, typename Tp2>
inline Tp2
stupid_cast (const Tp1& arg) { return static_cast<Tp2>(arg); }

BOOST_AUTO_TEST_CASE( test_details_key )
{
  BOOST_CHECK((stupid_cast<float, int>(1.0) == 1)); // <----- I
wrapped it in parenthesis
}

So I was wondering whether the BOOST_<level> macro (I did check that
the others suffer the same problem) are expected to behave in this
way, or they are just missing an extra layer of parenthesis around the
arguments, or even GCC is at fault, or I'm missing something
definitely...

Regards,
Sylvain


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk