xref: /Universal-ctags/Units/parser-cxx.r/variables-in-control-statements.d/input.cpp (revision f48878c797b8660fba2cb3697d13d9fe65ec4aa8)
1 #include <string>
2 #include <memory>
3 
4 // Helpers (should be hidden in ctags output)
5 
getUShort()6 unsigned short int getUShort()
7 {
8 	return 10;
9 }
10 
getPointer()11 int * getPointer()
12 {
13 	return 0;
14 }
15 
16 int n01;
17 unsigned short n02;
18 int * n03;
19 
20 typedef int INT;
21 
n04()22 int n04()
23 {
24 	return 0;
25 }
26 
27 int n05,n06,n07,n08,n09,n10,n11,n12,n13,n14,n15,n16;
28 
func(int no)29 template<typename T> func(int no){ return no; };
30 
31 // The real test starts here
32 
test()33 void test()
34 {
35 	// Valid variable declarations inside a for loop control structure
36 	for(int f01=0;f01<10;f01++)
37 	{
38 	}
39 
40 	for(int f02 = getUShort(), * f03 = getPointer();f03 < (getPointer() + 10);f03++)
41 	{
42 	}
43 
44 	for(int f04=0,f05=5,f06=10;f04<10;f04++)
45 	{
46 	}
47 
48 	for(std::string f07 = "test";;)
49 	{
50 	}
51 
52 	for(int f08 : { 1,2,3,4,5 })
53 	{
54 	}
55 
56 	for(std::unique_ptr<int> f09 = 0;;)
57 	{
58 	}
59 
60 	for(std::unique_ptr<int> f10(getPointer());;)
61 	{
62 	}
63 
64 	for(std::pair<int,int> f11;;)
65 	{
66 	}
67 
68 	for(auto f12 : { 't','e','s','t' })
69 	{
70 	}
71 
72 	// Non valid variable declarations inside for
73 	for(;;)
74 	{
75 	}
76 
77 	for(n01 = 0;n01 < 10;n01++)
78 	{
79 	}
80 
81 	for(n02 = getUShort(), n03 = getPointer();;)
82 	{
83 	}
84 
85 	for(n04();n04();)
86 	{
87 	}
88 
89 	// Valid variable declaration inside an if
90 	if(int i01 = 10 + 20)
91 	{
92 	}
93 
94 	if(INT * i02 = 0)
95 	{
96 	}
97 
98 	if(INT & i03 = n01)
99 	{
100 	}
101 
102 	// non valid declarations inside if
103 	if(n05 & n06)
104 	{
105 	}
106 
107 	if(n07 * n08)
108 	{
109 	}
110 
111 	if(n09 && n10)
112 	{
113 	}
114 
115 	if(n11 < n12 || n13 > n14)
116 	{
117 	}
118 
119 	if(static_cast<short>(n15) < n14)
120 	{
121 	}
122 
123 	if(func<int>(n16))
124 	{
125 	}
126 
127 	// Valid variable declarations inside a while
128 	while(unsigned short int w01 = getUShort())
129 	{
130 	}
131 }