Debian Codegraph @

gcc/testsuite/g++.dg/ext/label15.C

raw
1 // PR c++/37722
2 // { dg-do compile { target indirect_jumps } }
3 // { dg-options "" }
4
5 extern "C" int printf (const char *, ...);
6 template<int i>
7 struct foo {
8 foo() { printf("%s<%d>\n", __FUNCTION__, i); }
9 ~foo() { printf("%s<%d>\n", __FUNCTION__, i); }
10 };
11 enum {RETRY, INSIDE, OUTSIDE, EVIL};
12 int bar(int idx) {
13 static void* const gotos[] = {&&RETRY, &&INSIDE, &&OUTSIDE, &&EVIL};
14 bool first = true;
15 {
16 RETRY: // { dg-warning "jump" }
17 foo<1> f1; // { dg-message "does not destroy" }
18 if(first) {
19 first = false;
20 goto *gotos[idx]; // { dg-message "computed goto" }
21 }
22 INSIDE: // OK
23 return 1;
24 }
25 if(0) {
26 foo<2> f2; // { dg-message "crosses initialization" }
27 EVIL: // { dg-warning "jump" }
28 return 2;
29 }
30 OUTSIDE: // { dg-warning "jump" }
31 return 0;
32 }
33 int main() {
34 for(int i=RETRY; i <= EVIL; i++)
35 printf("%d\n", bar(i));
36 return 0;
37 }