summaryrefslogtreecommitdiff
path: root/test/SemaCXX/goto.cpp
blob: 24bcb7c5167383479addfcfb0a2849c423460403 (plain)
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
// RUN: %clang_cc1 -fsyntax-only -verify -Wall -fblocks %s

// PR9463
double *end;
void f(bool b1, bool b2) {
  {
    do {
      int end = 0;
      if (b2) {
        do {
          goto end;
        } while (b2);
      }
      end = 1;
    } while (b1);
  }

 end:
  return;
}

namespace N {
  float* end;
  void f(bool b1, bool b2) {
    {
      do {
        int end = 0;
        if (b2) {
          do {
            goto end;
          } while (b2);
        }
        end = 1;
      } while (b1);
    }

  end:
    return;
  }
}

void g() {
  end = 1; // expected-error{{assigning to 'double *' from incompatible type 'int'}}
}

void h(int end) {
  {
    goto end; // expected-error{{use of undeclared label 'end'}}
  }
}

void h2(int end) {
  {
    __label__ end;
    goto end;

  end:
    ::end = 0;
  }
 end: // expected-warning{{unused label 'end'}}
  end = 1;
}

class X {
public:
  X();
};

void rdar9135994()
{
X:  
    goto X;
}

namespace PR9495 {
  struct NonPOD { NonPOD(); ~NonPOD(); };  
  
  void f(bool b) {
    NonPOD np;
    if (b) {
      goto undeclared; // expected-error{{use of undeclared label 'undeclared'}}
    }
  }

  void g() {
    (void)^(bool b){
      NonPOD np;
      if (b) {
        goto undeclared; // expected-error{{use of undeclared label 'undeclared'}}
      }
    };
  }
}

extern "C" {
  void exit(int);
}

void f() {
  {
    goto exit;
  }
 exit:
  return;
}

namespace PR10620 {
  struct S {
    ~S() {}
  };
  void g(const S& s) {
    goto done; // expected-error {{goto into protected scope}}
    const S s2(s); // expected-note {{jump bypasses variable initialization}}
  done:
    ;
  }
}

namespace test12 {
  struct A { A(); A(const A&); ~A(); };
  void test(A a) { // expected-note {{jump enters lifetime of block}} FIXME: wierd location
    goto lbl; // expected-error {{goto into protected scope}}
    (void) ^{ (void) a; };
  lbl:
    return;
  }
}