1
#ifndef BOOST_SERIALIZATION_STATIC_WARNING_HPP
2
#define BOOST_SERIALIZATION_STATIC_WARNING_HPP
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) && (_MSC_VER >= 1020)
12
// http://www.boost.org/LICENSE_1_0.txt)
14
// See http://www.boost.org/libs/static_assert for documentation.
18
15 June 2003 - Initial version.
19
31 March 2004 - improved diagnostic messages and portability
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.
27
30 May 2004 - tweaked for msvc 7.1 and gcc 3.3
28
- static warnings ENabled by default; when enabled,
32
#include <boost/config.hpp>
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.
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
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.
58
//------------------Enable selected warnings----------------------------------//
60
// Enable the warnings relied on by BOOST_STATIC_WARNING, where possible. The
61
// only pragma which is absolutely necessary here is for Borland 5.x, since
62
// W8073 is disabled by default. If enabling selected warnings is considered
63
// unacceptable, this section can be replaced with:
64
// #if defined(__BORLANDC__) && (__BORLANDC__ <= 0x600)
68
// 6. replaced implementation with one which depends solely on
69
// mpl::print<>. The previous one was found to fail for functions
70
// under recent versions of gcc and intel compilers - Robert Ramey
72
#include <boost/mpl/bool.hpp>
73
#include <boost/mpl/print.hpp>
74
#include <boost/mpl/eval_if.hpp>
77
namespace serialization {
80
struct BOOST_SERIALIZATION_STATIC_WARNING_LINE{};
82
template<bool B, int L>
83
struct static_warning_test{
84
typename boost::mpl::eval_if_c<
87
typename boost::mpl::identity<
89
BOOST_SERIALIZATION_STATIC_WARNING_LINE<L>
96
struct BOOST_SERIALIZATION_SS {};
101
#define BOOST_SERIALIZATION_BSW(B, L) \
102
typedef boost::serialization::BOOST_SERIALIZATION_SS< \
103
sizeof( boost::serialization::static_warning_test< B, L > ) \
104
> BOOST_JOIN(STATIC_WARNING_LINE, L);
106
#define BOOST_STATIC_WARNING(B) BOOST_SERIALIZATION_BSW(B, __LINE__)
108
#endif // BOOST_SERIALIZATION_STATIC_WARNING_HPP