Chris@16: #ifndef BOOST_SERIALIZATION_STATIC_WARNING_HPP Chris@16: #define BOOST_SERIALIZATION_STATIC_WARNING_HPP Chris@16: Chris@16: // (C) Copyright Robert Ramey 2003. Jonathan Turkanis 2004. Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/libs/static_assert for documentation. Chris@16: Chris@16: /* Chris@16: Revision history: Chris@16: 15 June 2003 - Initial version. Chris@16: 31 March 2004 - improved diagnostic messages and portability Chris@16: (Jonathan Turkanis) Chris@16: 03 April 2004 - works on VC6 at class and namespace scope Chris@16: - ported to DigitalMars Chris@16: - static warnings disabled by default; when enabled, Chris@16: uses pragmas to enable required compiler warnings Chris@16: on MSVC, Intel, Metrowerks and Borland 5.x. Chris@16: (Jonathan Turkanis) Chris@16: 30 May 2004 - tweaked for msvc 7.1 and gcc 3.3 Chris@16: - static warnings ENabled by default; when enabled, Chris@16: (Robert Ramey) Chris@16: */ Chris@16: Chris@16: #include Chris@16: Chris@16: // Chris@16: // Implementation Chris@16: // Makes use of the following warnings: Chris@16: // 1. GCC prior to 3.3: division by zero. Chris@16: // 2. BCC 6.0 preview: unreferenced local variable. Chris@16: // 3. DigitalMars: returning address of local automatic variable. Chris@16: // 4. VC6: class previously seen as struct (as in 'boost/mpl/print.hpp') Chris@16: // 5. All others: deletion of pointer to incomplete type. Chris@16: // Chris@16: // The trick is to find code which produces warnings containing the name of Chris@16: // a structure or variable. Details, with same numbering as above: Chris@16: // 1. static_warning_impl::value is zero iff B is false, so diving an int Chris@16: // by this value generates a warning iff B is false. Chris@16: // 2. static_warning_impl::type has a constructor iff B is true, so an Chris@16: // unreferenced variable of this type generates a warning iff B is false. Chris@16: // 3. static_warning_impl::type overloads operator& to return a dynamically Chris@16: // allocated int pointer only is B is true, so returning the address of an Chris@16: // automatic variable of this type generates a warning iff B is fasle. Chris@16: // 4. static_warning_impl::STATIC_WARNING is decalred as a struct iff B is Chris@16: // false. Chris@16: // 5. static_warning_impl::type is incomplete iff B is false, so deleting a Chris@16: // pointer to this type generates a warning iff B is false. Chris@16: // Chris@16: Chris@16: //------------------Enable selected warnings----------------------------------// Chris@16: Chris@16: // Enable the warnings relied on by BOOST_STATIC_WARNING, where possible. The Chris@16: // only pragma which is absolutely necessary here is for Borland 5.x, since Chris@16: // W8073 is disabled by default. If enabling selected warnings is considered Chris@16: // unacceptable, this section can be replaced with: Chris@16: // #if defined(__BORLANDC__) && (__BORLANDC__ <= 0x600) Chris@16: // pragma warn +st Chris@16: // #endif Chris@16: Chris@16: // 6. replaced implementation with one which depends solely on Chris@16: // mpl::print<>. The previous one was found to fail for functions Chris@16: // under recent versions of gcc and intel compilers - Robert Ramey Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace serialization { Chris@16: Chris@16: template Chris@16: struct BOOST_SERIALIZATION_STATIC_WARNING_LINE{}; Chris@16: Chris@16: template Chris@16: struct static_warning_test{ Chris@16: typename boost::mpl::eval_if_c< Chris@16: B, Chris@16: boost::mpl::true_, Chris@16: typename boost::mpl::identity< Chris@16: boost::mpl::print< Chris@16: BOOST_SERIALIZATION_STATIC_WARNING_LINE Chris@16: > Chris@16: > Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct BOOST_SERIALIZATION_SS {}; Chris@16: Chris@16: } // serialization Chris@16: } // boost Chris@16: Chris@16: #define BOOST_SERIALIZATION_BSW(B, L) \ Chris@16: typedef boost::serialization::BOOST_SERIALIZATION_SS< \ Chris@16: sizeof( boost::serialization::static_warning_test< B, L > ) \ Chris@101: > BOOST_JOIN(STATIC_WARNING_LINE, L) BOOST_STATIC_ASSERT_UNUSED_ATTRIBUTE; Chris@16: #define BOOST_STATIC_WARNING(B) BOOST_SERIALIZATION_BSW(B, __LINE__) Chris@16: Chris@16: #endif // BOOST_SERIALIZATION_STATIC_WARNING_HPP