File: helper_macro_test.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (98 lines) | stat: -rw-r--r-- 1,829 bytes parent folder | download | duplicates (9)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//  (C) Copyright John Maddock 2014-9. 
//  (C) Copyright Andrey Semashev 2017. 
//  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) 

#include <boost/config.hpp>

int test_fallthrough(int n) 
{ 
   switch (n) 
   { 
   case 0: 
      n++; 
      BOOST_FALLTHROUGH; 
   case 1: 
      n++; 
      break; 
   } 
   return n; 
}

int test_unreachable(int i)
{
   if(BOOST_LIKELY(i)) return i;

   throw i;
   BOOST_UNREACHABLE_RETURN(0)  // NOTE: no semicolon afterwards!!
}

BOOST_FORCEINLINE int always_inline(int i){ return ++i; }
BOOST_NOINLINE int never_inline(int i){ return ++i; }

BOOST_NORETURN void always_throw()
{
   throw 0;
}

struct BOOST_MAY_ALIAS aliasing_struct {};
typedef unsigned int BOOST_MAY_ALIAS aliasing_uint;

struct BOOST_ATTRIBUTE_NODISCARD nodiscard_struct {};

BOOST_ATTRIBUTE_NODISCARD int nodiscard_proc(int i)
{
   return i * i;
}


#define test_fallthrough(x) foobar(x)

struct empty {};
struct no_unique
{
   int a;
   BOOST_ATTRIBUTE_NO_UNIQUE_ADDRESS empty b;
};

template <bool b>
struct trait
{
   enum { value = b };
};

void* test_nullptr()
{
   return BOOST_NULLPTR;
}

int main()
{
   typedef int unused_type BOOST_ATTRIBUTE_UNUSED;
   try
   {
      int result = test_fallthrough BOOST_PREVENT_MACRO_SUBSTITUTION(0);
      BOOST_STATIC_CONSTANT(bool, value = 0);
      result += test_unreachable(1);
      result += always_inline(2);
      result += never_inline(3);
      if(BOOST_UNLIKELY(!result))
         always_throw();
      nodiscard_struct s;
      no_unique no_un;

      BOOST_IF_CONSTEXPR(trait<true>::value)
      {
         result += 2;
      }

      test_nullptr();
   }
   catch(int)
   {
      return 1;
   }
   return 0;
}