]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/config/test/helper_macro_test.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / config / test / helper_macro_test.cpp
CommitLineData
92f5a8d4
TL
1// (C) Copyright John Maddock 2014-9.
2// (C) Copyright Andrey Semashev 2017.
7c673cae
FG
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
9int 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
23int test_unreachable(int i)
24{
25 if(BOOST_LIKELY(i)) return i;
26
27 throw i;
92f5a8d4 28 BOOST_UNREACHABLE_RETURN(0) // NOTE: no semicolon afterwards!!
7c673cae
FG
29}
30
31BOOST_FORCEINLINE int always_inline(int i){ return ++i; }
32BOOST_NOINLINE int never_inline(int i){ return ++i; }
33
34BOOST_NORETURN void always_throw()
35{
36 throw 0;
37}
38
b32b8144
FG
39struct BOOST_MAY_ALIAS aliasing_struct {};
40typedef unsigned int BOOST_MAY_ALIAS aliasing_uint;
41
92f5a8d4
TL
42struct BOOST_ATTRIBUTE_NODISCARD nodiscard_struct {};
43
7c673cae
FG
44
45#define test_fallthrough(x) foobar(x)
46
92f5a8d4
TL
47struct empty {};
48struct no_unique
49{
50 int a;
51 BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS empty b;
52};
53
f67539c2
TL
54template <bool b>
55struct trait
56{
57 enum { value = b };
58};
59
7c673cae
FG
60
61int main()
62{
63 typedef int unused_type BOOST_ATTRIBUTE_UNUSED;
64 try
65 {
66 int result = test_fallthrough BOOST_PREVENT_MACRO_SUBSTITUTION(0);
67 BOOST_STATIC_CONSTANT(bool, value = 0);
68 result += test_unreachable(1);
69 result += always_inline(2);
70 result += never_inline(3);
71 if(BOOST_UNLIKELY(!result))
72 always_throw();
92f5a8d4
TL
73 nodiscard_struct s;
74 no_unique no_un;
f67539c2
TL
75
76 BOOST_IF_CONSTEXPR(trait<true>::value)
77 {
78 result += 2;
79 }
7c673cae
FG
80 }
81 catch(int)
82 {
83 return 1;
84 }
85 return 0;
86}
87