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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
// RUN: %clang_cc1 -fsyntax-only %s -verify
[[noreturn]] extern void noret();
[[noreturn]] extern void noret2();
extern void ordinary();
typedef void (*func_type)(void);
// Constant initialization.
void (* const const_fptr)() = noret;
[[noreturn]] void test_global_const() {
const_fptr();
}
const func_type const_fptr_cast = (func_type)noret2;
[[noreturn]] void test_global_cast() {
const_fptr_cast();
}
void (* const const_fptr_list)() = {noret};
[[noreturn]] void test_global_list() {
const_fptr_list();
}
const func_type const_fptr_fcast = func_type(noret2);
[[noreturn]] void test_global_fcast() {
const_fptr_fcast();
}
[[noreturn]] void test_local_const() {
void (* const fptr)() = noret;
fptr();
}
// Global variable assignment.
void (*global_fptr)() = noret;
[[noreturn]] void test_global_noassign() {
global_fptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_global_assign() {
global_fptr = noret;
global_fptr();
} // expected-warning {{function declared 'noreturn' should not return}}
// Local variable assignment.
[[noreturn]] void test_init() {
func_type func_ptr = noret;
func_ptr();
}
[[noreturn]] void test_assign() {
void (*func_ptr)(void);
func_ptr = noret;
func_ptr();
}
[[noreturn]] void test_override() {
func_type func_ptr;
func_ptr = ordinary;
func_ptr = noret;
func_ptr();
}
[[noreturn]] void test_if_all(int x) {
func_type func_ptr;
if (x > 0)
func_ptr = noret;
else
func_ptr = noret2;
func_ptr();
}
[[noreturn]] void test_if_mix(int x) {
func_type func_ptr;
if (x > 0)
func_ptr = noret;
else
func_ptr = ordinary;
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_if_opt(int x) {
func_type func_ptr = noret;
if (x > 0)
func_ptr = ordinary;
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_if_opt2(int x) {
func_type func_ptr = ordinary;
if (x > 0)
func_ptr = noret;
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_if_nest_all(int x, int y) {
func_type func_ptr;
if (x > 0) {
if (y > 0)
func_ptr = noret;
else
func_ptr = noret2;
} else {
if (y < 0)
func_ptr = noret2;
else
func_ptr = noret;
}
func_ptr();
}
[[noreturn]] void test_if_nest_mix(int x, int y) {
func_type func_ptr;
if (x > 0) {
if (y > 0)
func_ptr = noret;
else
func_ptr = noret2;
} else {
if (y < 0)
func_ptr = ordinary;
else
func_ptr = noret;
}
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_switch_all(int x) {
func_type func_ptr;
switch(x) {
case 1:
func_ptr = noret;
break;
default:
func_ptr = noret2;
break;
}
func_ptr();
}
[[noreturn]] void test_switch_mix(int x) {
func_type func_ptr;
switch(x) {
case 1:
func_ptr = ordinary;
break;
default:
func_ptr = noret;
break;
}
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_switch_fall(int x) {
func_type func_ptr;
switch(x) {
case 1:
func_ptr = ordinary;
default:
func_ptr = noret;
break;
}
func_ptr();
}
[[noreturn]] void test_switch_all_nest(int x, int y) {
func_type func_ptr;
switch(x) {
case 1:
func_ptr = noret;
break;
default:
if (y > 0)
func_ptr = noret2;
else
func_ptr = noret;
break;
}
func_ptr();
}
[[noreturn]] void test_switch_mix_nest(int x, int y) {
func_type func_ptr;
switch(x) {
case 1:
func_ptr = noret;
break;
default:
if (y > 0)
func_ptr = noret2;
else
func_ptr = ordinary;
break;
}
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
// Function parameters.
[[noreturn]] void test_param(void (*func_ptr)() = noret) {
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_const_param(void (* const func_ptr)() = noret) {
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
// Escaped value.
extern void abc_01(func_type &);
extern void abc_02(func_type *);
[[noreturn]] void test_escape_ref() {
func_type func_ptr = noret;
abc_01(func_ptr);
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
[[noreturn]] void test_escape_addr() {
func_type func_ptr = noret;
abc_02(&func_ptr);
func_ptr();
} // expected-warning {{function declared 'noreturn' should not return}}
|