summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/serialization/test/test_static_warning.cpp
blob: 642b9cf3aad53b417d103f4acce11e17f08e6325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//  (C) Copyright Jonathan Turkanis 2004.
//  Use, modification and distribution are subject to the
//  Boost Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org for most recent version including documentation.

// note: this is a compile only test.

#include <boost/config.hpp> // BOOST_STATIC_CONST
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_polymorphic.hpp>

#include <boost/serialization/static_warning.hpp>

typedef char a1[2];
typedef char a2[3];

class polymorphic {
    virtual ~polymorphic();
};

class non_polymorphic {
};

template<class T>
int f(){
    BOOST_STATIC_WARNING(T::value);
    return 0;
}

struct A {
    BOOST_STATIC_CONSTANT(bool, value = false);
};

/////////////////////////////////////////////////////////////////////////
// compilation of this program should show a total of 10 warning messages

// should show NO warning message
BOOST_STATIC_WARNING(true);

// the following should show 5 warning message
int x = f<A>();  // Warn
int y = f<boost::is_polymorphic<non_polymorphic> >(); // Warn.
int z = f<boost::is_polymorphic<polymorphic> >();

BOOST_STATIC_WARNING(sizeof(a1) == sizeof(a2)); // Warn.
BOOST_STATIC_WARNING(sizeof(a1) != sizeof(a1)); // Warn.
BOOST_STATIC_WARNING(! boost::is_polymorphic<polymorphic>::value); // Warn.
BOOST_STATIC_WARNING(boost::is_polymorphic<non_polymorphic>::value); // Warn.

int main(int /* argc */, char * /* argv */[]){
    // should show NO warning message
    BOOST_STATIC_WARNING(true);

    // the following should show 5 warning message
    f<A>();
    BOOST_STATIC_WARNING(sizeof(a1) == sizeof(a2)); // Warn.
    BOOST_STATIC_WARNING(sizeof(a1) != sizeof(a1)); // Warn.
    BOOST_STATIC_WARNING(! boost::is_polymorphic<polymorphic>::value); // Warn.
    BOOST_STATIC_WARNING(boost::is_polymorphic<non_polymorphic>::value); // Warn.
    return 0;
}