Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8d9c991062e39ac7966d208531e0c20ca8f8f0a (plain) (blame)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*******************************************************************************
* Copyright (c) 2016 Institute for Software, HSR Hochschule fuer Technik 
* Rapperswil, University of applied sciences and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2.cxx14.constexpr;

import junit.framework.TestSuite;

public class ArrayTests extends TestBase {
	public static class NonIndexing extends ArrayTests {
		public NonIndexing() {setStrategy(new NonIndexingTestStrategy());}
		public static TestSuite suite() {return suite(NonIndexing.class);}
	}
	
	public static class SingleProject extends ArrayTests {
		public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true, false));}
		public static TestSuite suite() {return suite(SingleProject.class);}
	}
	
	// constexpr int f() {
	//	int foo[3][2] { {1,2}, {2, 3},{ 4, 5} };
	//	return foo[2][1];
	// }

	// constexpr int x = f();
	public void testInitializationOfMultiDimensionalArrays() throws Exception {
		assertEvaluationEquals(5);
	}
	
	// constexpr int f() {
	//	int foo[3] { 1, 2, 3 };
	//	foo[1] = foo[0] + foo[2];
	//  return foo[1];
	// }

	// constexpr int x = f();
	public void testAssignmentOfArrays() throws Exception {
		assertEvaluationEquals(4);
	}
	
	// constexpr int f() {
	//	int foo[3][2] { {1,2}, {2, 3},{ 4, 5} };
	//	foo[0][1] = 3;
	//  return foo[0][1];
	// }

	// constexpr int x = f();
	public void testAssignmentOfMultiDimensionalArrays() throws Exception {
		assertEvaluationEquals(3);
	}
	
	//	constexpr int a[2][2] { { 1, 2 }, { 3, 4 } };
	//	constexpr int f() {
	//		return a[0][0];
	//	}
	
	//	constexpr auto x = f();
	public void testGlobalArrayAccessValue() throws Exception {
		assertEvaluationEquals(1);
	}
	
	// constexpr int f() {
	//  int x[2][2] { { 1, 2 }, { 3, 4 } };
	//  int &xref { x[1][1] };
	//  int &xref2 { x[1][1] };
	//  xref++;
	//  xref = xref * xref2;
	//  return x[1][1];
	// }
	
	// constexpr auto x = f();
	public void testReferenceToArrayCell() throws Exception {
		assertEvaluationEquals(25);
	}
	
	//	constexpr int f() {
	//		int bar[2] { 3, 7 };
	//		(*bar)++;
	//		return bar[0];
	//	}
	
	//	constexpr int x = f();
	public void testPointerDereferencingOnArrayName() throws Exception {
		assertEvaluationEquals(4);
	}
	
	//	class S {
	//		int arr[4];
	//	public:
	//		constexpr S():arr{5,6,7,8} {}
	//		constexpr int *getPtr() {
	//			return arr;
	//		}
	//	};
	//	constexpr int f() {
	//		S s{};
	//		int *ptr = s.getPtr();
	//		return *ptr;
	//	}
	
	//	constexpr int x = f();
	public void testPointerToArrayReturnedFromMemberFunction1() throws Exception {
		assertEvaluationEquals(5);
	}
	
	//	class S {
	//		int arr[4];
	//	public:
	//		constexpr S():arr{5,7,9,11} {}
	//		constexpr int *getPtr() {
	//			return arr;
	//		}
	//	};
	//	constexpr int f() {
	//		S s{};
	//		int *ptr = s.getPtr();
	//		ptr += 2;
	//		return *ptr;
	//	}
	
	//	constexpr int x = f();
	public void testPointerToArrayReturnedFromMemberFunction2() throws Exception {
		assertEvaluationEquals(9);
	}

	//	class S {
	//		int arr[4];
	//	public:
	//	  constexpr S():arr{5,7,9,11} {}
	//	  constexpr int *getBegin() {
	//	    return arr;
	//	  }
	//	  constexpr int *getEnd() {
	//	    return arr + 4;
	//	  }
	//	};
	//
	//	constexpr int f() {
	//	  S s{};
	//	  int *begin = s.getBegin();
	//	  int *end = s.getEnd();
	//	  int sum = 0;
	//	  for(; begin != end; begin++) {
	//	    sum += *begin;
	//	  }
	//	  return sum;
	//	}
	
	//	constexpr int x = f();
	public void testPointerToArrayReturnedFromMemberFunction3() throws Exception {
		assertEvaluationEquals(32);
	}
	
	//	constexpr int f() {
	//		int arr[] = {1, 2, 3};
	//		int (&arrRef)[3] = arr;
	//		return arrRef[2];
	//	}
	
	//	constexpr int x = f();
	public void testReferenceToArray1() throws Exception {
		assertEvaluationEquals(3);
	}
	
	//	constexpr int f() {
	//		int arr[] = {1, 2, 3};
	//		int (&arrRef)[3] = arr;
	//		arrRef[2] *= 2;
	//		return arr[2];
	//	}
	
	//	constexpr int x = f();
	public void testReferenceToArray2() throws Exception {
		assertEvaluationEquals(6);
	}
	
	//	constexpr int f() {
	//		int arr[] = {1, 2, 3};
	//		int (&arrRef)[3] = arr;
	//		for(int& i : arrRef) {
	//			i *= 2;
	//		}
	//		return arr[2];
	//	}
	
	//	constexpr int x = f();
	public void testReferenceToArray3() throws Exception {
		assertEvaluationEquals(6);
	}
	
	//	constexpr int f() {
	//		int bar[2][2] { { 3, 5 }, {7, 11 } };
	//		int * bar_ptr { bar[1] };
	//		(*bar_ptr)++;
	//		return *bar_ptr;
	//	}
	
	//	constexpr int x = f();
	public void testPointerArithmeticsOnMultidimensionalArray() throws Exception {
		assertEvaluationEquals(8);
	}
	
	//	constexpr void g(int * array) {
	//		array[0] = 1337;
	//	}
	//	constexpr int f() {
	//		int bar[2] { 1, 2 };
	//		g(bar);
	//		return bar[0];
	//	}
	
	//	constexpr int x = f();
	public void testPassArrayToFunctionAsPointerAndModifyCell() throws Exception {
		assertEvaluationEquals(1337);
	}
	
	//	constexpr void g(int array[2][2]) {
	//		array[1][0] = 1337;
	//	}
	//	constexpr int f() {
	//		int bar[2][2] { { 3, 5 }, { 7, 11 } };
	//		g(bar);
	//		return bar[1][0];
	//	}
	
	//	constexpr int x = f();
	public void testPassMultiDimensionalArrayToFunctionAsPointerAndModifyCell() throws Exception {
		assertEvaluationEquals(1337);
	}
	
	// constexpr int f() {
	//	int foo[] { 1, 2, 3, 4, 5 };
	//	return foo[2];
	// }
	
	// constexpr int x = f();
	public void testInitializationOfArrays() throws Exception {
		assertEvaluationEquals(3);
	}
}

Back to the top