summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/goto.cpp
blob: d8d5ec51f6e40f518cf69b1625f67c6b9d74d8d1 (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
// 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;
}