xref: /llvm-project/clang/test/SemaCXX/goto2.cpp (revision ac524886094db58112ca176e1d727330a94634a8)
1 // RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++17 %s
2 // expected-no-diagnostics
3 
4 //PR9463
subfun(const char * text)5 int subfun(const char *text) {
6   const char *tmp = text;
7   return 0;
8 }
9 
fun(const char * text)10 void fun(const char* text) {
11   int count = 0;
12   bool check = true;
13 
14   if (check)
15     {
16       const char *end = text;
17 
18       if (check)
19         {
20           do
21             {
22               if (check)
23                 {
24                   count = subfun(end);
25                   goto end;
26                 }
27 
28               check = !check;
29             }
30           while (check);
31         }
32       // also works, after commenting following line of source code
33       int e = subfun(end);
34     }
35  end:
36   if (check)
37     ++count;
38 }
39 
40 const char *text = "some text";
41 
main()42 int main() {
43 	const char *ptr = text;
44 
45 	fun(ptr);
46 
47 	return 0;
48 }
49 
asm_goto_try_catch()50 void asm_goto_try_catch() {
51   try {
52     __label__ label;
53     asm goto("" : : : : label);
54     label:;
55   } catch(...) {
56     __label__ label;
57     asm goto("" : : : : label);
58     label:;
59   };
60   if constexpr(false) {
61     __label__ label;
62     asm goto("" : : : : label);
63     label:;
64   }
65 }
66