Brian Silverman | 8867871 | 2018-08-04 23:56:48 -0700 | [diff] [blame^] | 1 | #ifndef BOOST_SERIALIZATION_STATIC_WARNING_HPP |
| 2 | #define BOOST_SERIALIZATION_STATIC_WARNING_HPP |
| 3 | |
| 4 | // (C) Copyright Robert Ramey 2003. Jonathan Turkanis 2004. |
| 5 | // Use, modification and distribution is subject to the Boost Software |
| 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // MS compatible compilers support #pragma once |
| 8 | #if defined(_MSC_VER) |
| 9 | # pragma once |
| 10 | #endif |
| 11 | |
| 12 | // http://www.boost.org/LICENSE_1_0.txt) |
| 13 | |
| 14 | // See http://www.boost.org/libs/static_assert for documentation. |
| 15 | |
| 16 | /* |
| 17 | Revision history: |
| 18 | 15 June 2003 - Initial version. |
| 19 | 31 March 2004 - improved diagnostic messages and portability |
| 20 | (Jonathan Turkanis) |
| 21 | 03 April 2004 - works on VC6 at class and namespace scope |
| 22 | - ported to DigitalMars |
| 23 | - static warnings disabled by default; when enabled, |
| 24 | uses pragmas to enable required compiler warnings |
| 25 | on MSVC, Intel, Metrowerks and Borland 5.x. |
| 26 | (Jonathan Turkanis) |
| 27 | 30 May 2004 - tweaked for msvc 7.1 and gcc 3.3 |
| 28 | - static warnings ENabled by default; when enabled, |
| 29 | (Robert Ramey) |
| 30 | */ |
| 31 | |
| 32 | #include <boost/config.hpp> |
| 33 | |
| 34 | // |
| 35 | // Implementation |
| 36 | // Makes use of the following warnings: |
| 37 | // 1. GCC prior to 3.3: division by zero. |
| 38 | // 2. BCC 6.0 preview: unreferenced local variable. |
| 39 | // 3. DigitalMars: returning address of local automatic variable. |
| 40 | // 4. VC6: class previously seen as struct (as in 'boost/mpl/print.hpp') |
| 41 | // 5. All others: deletion of pointer to incomplete type. |
| 42 | // |
| 43 | // The trick is to find code which produces warnings containing the name of |
| 44 | // a structure or variable. Details, with same numbering as above: |
| 45 | // 1. static_warning_impl<B>::value is zero iff B is false, so diving an int |
| 46 | // by this value generates a warning iff B is false. |
| 47 | // 2. static_warning_impl<B>::type has a constructor iff B is true, so an |
| 48 | // unreferenced variable of this type generates a warning iff B is false. |
| 49 | // 3. static_warning_impl<B>::type overloads operator& to return a dynamically |
| 50 | // allocated int pointer only is B is true, so returning the address of an |
| 51 | // automatic variable of this type generates a warning iff B is fasle. |
| 52 | // 4. static_warning_impl<B>::STATIC_WARNING is decalred as a struct iff B is |
| 53 | // false. |
| 54 | // 5. static_warning_impl<B>::type is incomplete iff B is false, so deleting a |
| 55 | // pointer to this type generates a warning iff B is false. |
| 56 | // |
| 57 | |
| 58 | //------------------Enable selected warnings----------------------------------// |
| 59 | |
| 60 | // Enable the warnings relied on by BOOST_STATIC_WARNING, where possible. |
| 61 | |
| 62 | // 6. replaced implementation with one which depends solely on |
| 63 | // mpl::print<>. The previous one was found to fail for functions |
| 64 | // under recent versions of gcc and intel compilers - Robert Ramey |
| 65 | |
| 66 | #include <boost/mpl/bool.hpp> |
| 67 | #include <boost/mpl/print.hpp> |
| 68 | #include <boost/mpl/eval_if.hpp> |
| 69 | #include <boost/mpl/bool_fwd.hpp> |
| 70 | #include <boost/static_assert.hpp> |
| 71 | |
| 72 | namespace boost { |
| 73 | namespace serialization { |
| 74 | |
| 75 | template<int L> |
| 76 | struct BOOST_SERIALIZATION_STATIC_WARNING_LINE{}; |
| 77 | |
| 78 | template<bool B, int L> |
| 79 | struct static_warning_test{ |
| 80 | typename boost::mpl::eval_if_c< |
| 81 | B, |
| 82 | boost::mpl::true_, |
| 83 | typename boost::mpl::identity< |
| 84 | boost::mpl::print< |
| 85 | BOOST_SERIALIZATION_STATIC_WARNING_LINE<L> |
| 86 | > |
| 87 | > |
| 88 | >::type type; |
| 89 | }; |
| 90 | |
| 91 | template<int i> |
| 92 | struct BOOST_SERIALIZATION_SS {}; |
| 93 | |
| 94 | } // serialization |
| 95 | } // boost |
| 96 | |
| 97 | #define BOOST_SERIALIZATION_BSW(B, L) \ |
| 98 | typedef boost::serialization::BOOST_SERIALIZATION_SS< \ |
| 99 | sizeof( boost::serialization::static_warning_test< B, L > ) \ |
| 100 | > BOOST_JOIN(STATIC_WARNING_LINE, L) BOOST_ATTRIBUTE_UNUSED; |
| 101 | #define BOOST_STATIC_WARNING(B) BOOST_SERIALIZATION_BSW(B, __LINE__) |
| 102 | |
| 103 | #endif // BOOST_SERIALIZATION_STATIC_WARNING_HPP |