1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2002-2020 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 struct aggregate 19 { 20 int i1; 21 int i2; 22 int i3; 23 }; 24 25 void keepalive_float (double *var) { } 26 void keepalive_int (int *var) { } 27 void keepalive_aggregate (struct aggregate *var) { } 28 29 #define PREFIXIFY(PREFIX, VAR) \ 30 PREFIX ## _ ## VAR 31 32 #define DEF_STATICS(PREFIX) \ 33 static int PREFIXIFY(PREFIX, s_var_int) = 4; \ 34 static double PREFIXIFY(PREFIX, s_var_float) = 3.14f; \ 35 static struct aggregate PREFIXIFY(PREFIX, s_var_aggregate) \ 36 = { 1, 2, 3 }; \ 37 \ 38 keepalive_int (&PREFIXIFY(PREFIX, s_var_int)); \ 39 keepalive_float (&PREFIXIFY(PREFIX, s_var_float)); \ 40 keepalive_aggregate (&PREFIXIFY(PREFIX, s_var_aggregate)); 41 42 #ifdef __cplusplus 43 44 struct S 45 { 46 void inline_method () 47 { 48 DEF_STATICS (S_IM); 49 } 50 static void static_inline_method () 51 { 52 DEF_STATICS (S_SIM); 53 } 54 55 void method (); 56 void method () const; 57 void method () volatile; 58 void method () volatile const; 59 60 static void static_method (); 61 }; 62 63 S s; 64 const S c_s = {}; 65 volatile S v_s = {}; 66 const volatile S cv_s = {}; 67 68 void 69 S::method () 70 { 71 DEF_STATICS (S_M); 72 } 73 74 void 75 S::method () const 76 { 77 DEF_STATICS (S_M_C); 78 } 79 80 void 81 S::method () volatile 82 { 83 DEF_STATICS (S_M_V); 84 } 85 86 void 87 S::method () const volatile 88 { 89 DEF_STATICS (S_M_CV); 90 } 91 92 void 93 S::static_method () 94 { 95 DEF_STATICS (S_SM); 96 } 97 98 template <typename T> 99 struct S2 100 { 101 void method (); 102 static void static_method (); 103 104 void inline_method () 105 { 106 DEF_STATICS (S2_IM); 107 } 108 109 static void static_inline_method () 110 { 111 DEF_STATICS (S2_SIM); 112 } 113 }; 114 115 template<typename T> 116 void 117 S2<T>::method () 118 { 119 DEF_STATICS (S2_M); 120 } 121 122 template<typename T> 123 void 124 S2<T>::static_method () 125 { 126 DEF_STATICS (S2_SM); 127 } 128 129 S2<int> s2; 130 131 #endif 132 133 void 134 free_func (void) 135 { 136 DEF_STATICS (FF); 137 } 138 139 static inline void 140 free_inline_func (void) 141 { 142 DEF_STATICS (FIF); 143 } 144 145 int 146 main () 147 { 148 int i; 149 150 for (i = 0; i < 1000; i++) 151 { 152 free_func (); 153 free_inline_func (); 154 155 #ifdef __cplusplus 156 s.method (); 157 c_s.method (); 158 v_s.method (); 159 cv_s.method (); 160 s.inline_method (); 161 S::static_method (); 162 S::static_inline_method (); 163 164 s2.method (); 165 s2.inline_method (); 166 S2<int>::static_method (); 167 S2<int>::static_inline_method (); 168 #endif 169 } 170 171 return 0; 172 } 173