]> git.proxmox.com Git - ceph.git/blame - 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
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
7c673cae
FG
54
55int 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();
92f5a8d4
TL
67 nodiscard_struct s;
68 no_unique no_un;
7c673cae
FG
69 }
70 catch(int)
71 {
72 return 1;
73 }
74 return 0;
75}
76