]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/config/test/helper_macro_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / config / test / helper_macro_test.cpp
1 // (C) Copyright John Maddock 2014-9.
2 // (C) Copyright Andrey Semashev 2017.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/config.hpp>
8
9 int test_fallthrough(int n)
10 {
11 switch (n)
12 {
13 case 0:
14 n++;
15 BOOST_FALLTHROUGH;
16 case 1:
17 n++;
18 break;
19 }
20 return n;
21 }
22
23 int test_unreachable(int i)
24 {
25 if(BOOST_LIKELY(i)) return i;
26
27 throw i;
28 BOOST_UNREACHABLE_RETURN(0) // NOTE: no semicolon afterwards!!
29 }
30
31 BOOST_FORCEINLINE int always_inline(int i){ return ++i; }
32 BOOST_NOINLINE int never_inline(int i){ return ++i; }
33
34 BOOST_NORETURN void always_throw()
35 {
36 throw 0;
37 }
38
39 struct BOOST_MAY_ALIAS aliasing_struct {};
40 typedef unsigned int BOOST_MAY_ALIAS aliasing_uint;
41
42 struct BOOST_ATTRIBUTE_NODISCARD nodiscard_struct {};
43
44
45 #define test_fallthrough(x) foobar(x)
46
47 struct empty {};
48 struct no_unique
49 {
50 int a;
51 BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS empty b;
52 };
53
54
55 int main()
56 {
57 typedef int unused_type BOOST_ATTRIBUTE_UNUSED;
58 try
59 {
60 int result = test_fallthrough BOOST_PREVENT_MACRO_SUBSTITUTION(0);
61 BOOST_STATIC_CONSTANT(bool, value = 0);
62 result += test_unreachable(1);
63 result += always_inline(2);
64 result += never_inline(3);
65 if(BOOST_UNLIKELY(!result))
66 always_throw();
67 nodiscard_struct s;
68 no_unique no_un;
69 }
70 catch(int)
71 {
72 return 1;
73 }
74 return 0;
75 }
76