[test] CHECK_EQUAL and problem with class constants

Consider this simple example... #include <boost/test/test_tools.hpp> struct Foo { static unsigned int const x = 10; }; int test_main( int, char* [] ) // note the name! { BOOST_CHECK_EQUAL(10U, Foo::x); return 0; } At least under gcc, I get a linker error, unable to find Foo::x, while the following code works fine... int test_main( int, char* [] ) // note the name! { BOOST_CHECK(10U == Foo::x); return 0; }

"Jody Hagins" <jody-boost-011304@atdesk.com> wrote in message news:20050113121604.1f0f6ed0.jody-boost-011304@atdesk.com...
Consider this simple example...
#include <boost/test/test_tools.hpp>
struct Foo { static unsigned int const x = 10; };
int test_main( int, char* [] ) // note the name! { BOOST_CHECK_EQUAL(10U, Foo::x); return 0; }
At least under gcc, I get a linker error, unable to find Foo::x, while the following code works fine...
int test_main( int, char* [] ) // note the name! { BOOST_CHECK(10U == Foo::x); return 0; }
I remember very similar issue with MPL constants. I consider this a compiler bug and it could (and should) be workaround on struct Foo implementation level (did you try to use enum?) Gennadiy

Gennadiy Rozental wrote:
"Jody Hagins" <jody-boost-011304@atdesk.com> wrote in message news:20050113121604.1f0f6ed0.jody-boost-011304@atdesk.com...
Consider this simple example...
#include <boost/test/test_tools.hpp>
struct Foo { static unsigned int const x = 10; };
int test_main( int, char* [] ) // note the name! { BOOST_CHECK_EQUAL(10U, Foo::x); return 0; }
At least under gcc, I get a linker error, unable to find Foo::x, while the following code works fine...
int test_main( int, char* [] ) // note the name! { BOOST_CHECK(10U == Foo::x); return 0; }
I remember very similar issue with MPL constants. I consider this a compiler bug and it could (and should) be workaround on struct Foo implementation level (did you try to use enum?)
The compiler may be right (but I'm not up to date with the latest progress on the core issues). Foo::x is not defined. unsigned int const Foo::x; // in Foo.cpp should fix it.
participants (3)
-
Gennadiy Rozental
-
Jody Hagins
-
Peter Dimov