xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/goto2.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc // expected-no-diagnostics
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc //PR9463
subfun(const char * text)5*f4a2713aSLionel Sambuc int subfun(const char *text) {
6*f4a2713aSLionel Sambuc   const char *tmp = text;
7*f4a2713aSLionel Sambuc   return 0;
8*f4a2713aSLionel Sambuc }
9*f4a2713aSLionel Sambuc 
fun(const char * text)10*f4a2713aSLionel Sambuc void fun(const char* text) {
11*f4a2713aSLionel Sambuc   int count = 0;
12*f4a2713aSLionel Sambuc   bool check = true;
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc   if (check)
15*f4a2713aSLionel Sambuc     {
16*f4a2713aSLionel Sambuc       const char *end = text;
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc       if (check)
19*f4a2713aSLionel Sambuc         {
20*f4a2713aSLionel Sambuc           do
21*f4a2713aSLionel Sambuc             {
22*f4a2713aSLionel Sambuc               if (check)
23*f4a2713aSLionel Sambuc                 {
24*f4a2713aSLionel Sambuc                   count = subfun(end);
25*f4a2713aSLionel Sambuc                   goto end;
26*f4a2713aSLionel Sambuc                 }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc               check = !check;
29*f4a2713aSLionel Sambuc             }
30*f4a2713aSLionel Sambuc           while (check);
31*f4a2713aSLionel Sambuc         }
32*f4a2713aSLionel Sambuc       // also works, after commenting following line of source code
33*f4a2713aSLionel Sambuc       int e = subfun(end);
34*f4a2713aSLionel Sambuc     }
35*f4a2713aSLionel Sambuc  end:
36*f4a2713aSLionel Sambuc   if (check)
37*f4a2713aSLionel Sambuc     ++count;
38*f4a2713aSLionel Sambuc }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc const char *text = "some text";
41*f4a2713aSLionel Sambuc 
main()42*f4a2713aSLionel Sambuc int main() {
43*f4a2713aSLionel Sambuc 	const char *ptr = text;
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc 	fun(ptr);
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc 	return 0;
48*f4a2713aSLionel Sambuc }
49