]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/static_assert/static_assert_test.cpp
1 // (C) Copyright Steve Cleary & John Maddock 2000.
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)
6 // See http://www.boost.org for most recent version including documentation.
8 #include <boost/static_assert.hpp>
11 // all these tests should succeed.
12 // some of these tests are rather simplistic (ie useless)
13 // in order to ensure that they compile on all platforms.
17 BOOST_STATIC_ASSERT(sizeof(int) >= sizeof(short));
18 BOOST_STATIC_ASSERT(sizeof(char) == 1);
19 BOOST_STATIC_ASSERT_MSG(sizeof(int) >= sizeof(short), "msg1");
20 BOOST_STATIC_ASSERT_MSG(sizeof(char) == 1, "msg2");
22 // Function (block) scope
25 BOOST_STATIC_ASSERT(sizeof(int) >= sizeof(short));
26 BOOST_STATIC_ASSERT(sizeof(char) == 1);
27 BOOST_STATIC_ASSERT_MSG(sizeof(int) >= sizeof(short), "msg3");
28 BOOST_STATIC_ASSERT_MSG(sizeof(char) == 1, "msg4");
33 private: // can be in private, to avoid namespace pollution
34 BOOST_STATIC_ASSERT(sizeof(int) >= sizeof(short));
35 BOOST_STATIC_ASSERT(sizeof(char) == 1);
36 BOOST_STATIC_ASSERT_MSG(sizeof(int) >= sizeof(short), "msg5");
37 BOOST_STATIC_ASSERT_MSG(sizeof(char) == 1, "msg6");
40 // Member function scope: provides access to member variables
45 #if defined(_MSC_VER) && _MSC_VER < 1300 // broken sizeof in VC6
46 BOOST_STATIC_ASSERT(sizeof(x
) >= sizeof(short));
47 BOOST_STATIC_ASSERT(sizeof(c
) == 1);
48 BOOST_STATIC_ASSERT_MSG(sizeof(x
) >= sizeof(short), "msg7");
49 BOOST_STATIC_ASSERT_MSG(sizeof(c
) == 1, "msg8");
57 // Template class scope
58 template <class Int
, class Char
>
61 BOOST_STATIC_CONSTANT(int, value
= 1);
62 private: // can be in private, to avoid namespace pollution
63 BOOST_STATIC_ASSERT(sizeof(Int
) > sizeof(char));
64 BOOST_STATIC_ASSERT_MSG(sizeof(Int
) > sizeof(char), "msg9");
67 // Template member function scope: provides access to member variables
70 template <class Int2
, class Char2
>
73 BOOST_STATIC_ASSERT(sizeof(Int
) == sizeof(Int2
));
74 BOOST_STATIC_ASSERT(sizeof(Char
) == sizeof(Char2
));
75 BOOST_STATIC_ASSERT_MSG(sizeof(Int
) == sizeof(Int2
), "msg10");
76 BOOST_STATIC_ASSERT_MSG(sizeof(Char
) == sizeof(Char2
), "msg11");
80 void test_Bill() // BOOST_STATIC_ASSERTs are not triggerred until instantiated
83 //Bill<int, int> bad; // will not compile
87 //z.f(i, i); // should not compile
94 // Test variadic macro support:
96 #ifndef BOOST_NO_CXX11_VARIADIC_MACROS
97 BOOST_STATIC_ASSERT(Bill
<int, char>::value
);
98 #ifndef BOOST_NO_CXX11_STATIC_ASSERT
99 BOOST_STATIC_ASSERT_MSG(Bill
<int, char>::value
, "This is a message");