Opened 13 years ago

Closed 13 years ago

#2983 closed Bugs (fixed)

BOOST_CHECK_EQUAL gives error (or warning) "use of old-style cast" when compiled as C++

Reported by: anonymous Owned by: Gennadiy Rozental
Milestone: Boost 1.39.0 Component: test
Version: Boost 1.37.0 Severity: Problem
Keywords: Cc:

Description

BOOST_CHECK_EQUAL gives error (or warning) "use of old-style cast" when compiled as C++ (using g++ -Werror=old-style-cast). This is especially bad because we are supposed to use -Werror=old-style-cast in the build to keep our own code clean. Then BOOST gets in the way. We had similar issues with SDL: http://bugzilla.libsdl.org/show_bug.cgi?id=537 http://bugzilla.libsdl.org/show_bug.cgi?id=538

They accepted a fix that used special macros for casts: /* Use proper C++ casts when compiled as C++ to be compatible with the option + -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above. */ #ifdef cplusplus #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression) #define SDL_static_cast(type, expression) static_cast<type>(expression) #else #define SDL_reinterpret_cast(type, expression) ((type)(expression)) #define SDL_static_cast(type, expression) ((type)(expression)) #endif

With that simple technique they could get their headers to work cleanly with C++ while staying compatible with C. Boost should fix this issue too.

The following code shows how the bug can be reproduced: $ cat prov.cc #include <boost/test/unit_test.hpp> void f () {

BOOST_CHECK_EQUAL(0, 0);

} $ LANG= g++ -c -Werror=old-style-cast prov.cc prov.cc: In function 'void f()': prov.cc:3: error: use of old-style cast prov.cc:3: error: use of old-style cast

Change History (1)

comment:1 by Gennadiy Rozental, 13 years ago

Resolution: fixed
Status: newclosed

Boost.Test is C++ library. No need for macro. I've changed C style casts inside Boost.Test code. there might be still some coming from other components or system headers

Note: See TracTickets for help on using tickets.