[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / goto.cpp
blobb80305fefa4f591c13e85d1a35482a214a8baf6b
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wall -Wno-unused-but-set-variable -fblocks %s
3 // PR9463
4 double *end;
5 void f(bool b1, bool b2) {
7 do {
8 int end = 0;
9 if (b2) {
10 do {
11 goto end;
12 } while (b2);
14 end = 1;
15 } while (b1);
18 end:
19 return;
22 namespace N {
23 float* end;
24 void f(bool b1, bool b2) {
26 do {
27 int end = 0;
28 if (b2) {
29 do {
30 goto end;
31 } while (b2);
33 end = 1;
34 } while (b1);
37 end:
38 return;
42 void g() {
43 end = 1; // expected-error{{incompatible integer to pointer conversion assigning to 'double *' from 'int'}}
46 void h(int end) {
48 goto end; // expected-error{{use of undeclared label 'end'}}
52 void h2(int end) {
54 __label__ end;
55 goto end;
57 end:
58 ::end = 0;
60 end: // expected-warning{{unused label 'end'}}
61 end = 1;
64 class X {
65 public:
66 X();
69 void rdar9135994()
71 X:
72 goto X;
75 namespace PR9495 {
76 struct NonPOD { NonPOD(); ~NonPOD(); };
78 void f(bool b) {
79 NonPOD np;
80 if (b) {
81 goto undeclared; // expected-error{{use of undeclared label 'undeclared'}}
85 void g() {
86 (void)^(bool b){
87 NonPOD np;
88 if (b) {
89 goto undeclared; // expected-error{{use of undeclared label 'undeclared'}}
95 extern "C" {
96 void exit(int);
99 void f() {
101 goto exit;
103 exit:
104 return;
107 namespace PR10620 {
108 struct S {
109 ~S() {}
111 void g(const S& s) {
112 goto done; // expected-error {{cannot jump}}
113 const S s2(s); // expected-note {{jump bypasses variable initialization}}
114 done:
119 namespace test12 {
120 struct A { A(); A(const A&); ~A(); };
121 void test(A a) { // expected-note {{jump enters lifetime of block}} FIXME: weird location
122 goto lbl; // expected-error {{cannot jump}}
123 (void) ^{ (void) a; };
124 lbl:
125 return;