[Boost-bugs] [Boost C++ Libraries] #2983: BOOST_CHECK_EQUAL gives error (or warning) "use of old-style cast" when compiled as C++

Subject: [Boost-bugs] [Boost C++ Libraries] #2983: BOOST_CHECK_EQUAL gives error (or warning) "use of old-style cast" when compiled as C++
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-05-01 13:09:29


#2983: BOOST_CHECK_EQUAL gives error (or warning) "use of old-style cast" when
compiled as C++
--------------------------+-------------------------------------------------
 Reporter: anonymous | Owner: rogeeff
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: test
  Version: Boost 1.37.0 | Severity: Problem
 Keywords: |
--------------------------+-------------------------------------------------
 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

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2983>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC