1// (C) Copyright Jonathan Turkanis 2004.
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org for most recent version including documentation.
7
8// note: this is a compile only test.
9
10#include <boost/config.hpp> // BOOST_STATIC_CONST
11#include <boost/static_assert.hpp>
12#include <boost/type_traits/is_polymorphic.hpp>
13
14#include <boost/serialization/static_warning.hpp>
15
16typedef char a1[2];
17typedef char a2[3];
18
19class polymorphic {
20 virtual ~polymorphic();
21};
22
23class non_polymorphic {
24};
25
26template<class T>
27int f(){
28 BOOST_STATIC_WARNING(T::value);
29 return 0;
30}
31
32struct A {
33 BOOST_STATIC_CONSTANT(bool, value = false);
34};
35
36/////////////////////////////////////////////////////////////////////////
37// compilation of this program should show a total of 10 warning messages
38
39// should show NO warning message
40BOOST_STATIC_WARNING(true);
41
42// the following should show 5 warning message
43int x = f<A>(); // Warn
44int y = f<boost::is_polymorphic<non_polymorphic> >(); // Warn.
45int z = f<boost::is_polymorphic<polymorphic> >();
46
47BOOST_STATIC_WARNING(sizeof(a1) == sizeof(a2)); // Warn.
48BOOST_STATIC_WARNING(sizeof(a1) != sizeof(a1)); // Warn.
49BOOST_STATIC_WARNING(! boost::is_polymorphic<polymorphic>::value); // Warn.
50BOOST_STATIC_WARNING(boost::is_polymorphic<non_polymorphic>::value); // Warn.
51
52int main(int /* argc */, char * /* argv */[]){
53 // should show NO warning message
54 BOOST_STATIC_WARNING(true);
55
56 // the following should show 5 warning message
57 f<A>();
58 BOOST_STATIC_WARNING(sizeof(a1) == sizeof(a2)); // Warn.
59 BOOST_STATIC_WARNING(sizeof(a1) != sizeof(a1)); // Warn.
60 BOOST_STATIC_WARNING(! boost::is_polymorphic<polymorphic>::value); // Warn.
61 BOOST_STATIC_WARNING(boost::is_polymorphic<non_polymorphic>::value); // Warn.
62 return 0;
63}
64

source code of boost/libs/serialization/test/test_static_warning.cpp