Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 534595cb1a4cc8d36a1bd266fa1f16de54dbb14b (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
/*******************************************************************************
* Copyright (c) 2016 Institute for Software, HSR Hochschule fuer Technik 
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.ast2.cxx14.constexpr;

import junit.framework.TestSuite;

public class MemberFunctionTests extends TestBase {
	public static class NonIndexing extends MemberFunctionTests {
		public NonIndexing() {setStrategy(new NonIndexingTestStrategy());}
		public static TestSuite suite() {return suite(NonIndexing.class);}
	}
	
	public static class SingleProject extends MemberFunctionTests {
		public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true, false));}
		public static TestSuite suite() {return suite(SingleProject.class);}
	}
	
	//	struct S {
	//		int x, y;
	//		constexpr int member() {
	//			return 4;
	//		}
	//	};
	//	constexpr int f() {
	//		S s{3,7};
	//		return s.member();
	//	}
	
	//	constexpr auto x = f();
	public void testMemberFunctionCall() throws Exception {
		assertEvaluationEquals(4);
	}
	
	//	struct S {
	//		int x, y;
	//		constexpr int member() {
	//			y++;
	//			return y;
	//		}
	//	};
	//	constexpr int f() {
	//		S s{3,7};
	//		return s.member();
	//	}
	
	//	constexpr auto x = f();
	public void testMemberFunctionWithImplicitThis() throws Exception {
		assertEvaluationEquals(8);	
	}
	
	//	class Point {
	//		int x, y;
	//	public:
	//		constexpr Point(int x, int y):x{x}, y{y} {}
	//		constexpr int getY() const;
	//	};
	//	constexpr int Point::getY() const { return y; }
	//
	//	constexpr int f() {
	//	  Point p{4,5};
	//	  return p.getY();
	//	}
	
	//	constexpr int x = f();
	public void testExternallyDefinedMemberFunction() throws Exception {
		assertEvaluationEquals(5);
	}
	
	//	class S {
	//		int x;
	//	public:
	//		constexpr S(int x):x{x} {}
	//		constexpr void inc() { x += 30; }
	//		constexpr int get() const { return x; }
	//	};
	//
	//	constexpr int f() {
	//	  S s{20};
	//	  s.inc();
	//	  return s.get();
	//	}
	
	//	constexpr int x = f();
	public void testPlusEqualsWithinMemberFunction() throws Exception {
		assertEvaluationEquals(50);
	}
	
	//	class Point {
	//		int x, y;
	//	public:
	//		constexpr Point(int x, int y):x{x}, y{y} {}
	//		constexpr int getY() const { return this->y; }
	//	};
	//	constexpr int f() {
	//		Point p{10,40};
	//		return p.getY();
	//	}
	
	//	constexpr int x = f();
	public void testMemberAccessThroughThisPointer() throws Exception {
		assertEvaluationEquals(40);
	}
	
	//	struct S {
	//		int x, y;
	//		constexpr int member() {
	//			y = member2();
	//			return y;
	//		}
	//		constexpr int member2() {
	//			y++;
	//			return y;
	//		}
	//	};
	//	constexpr int f() {
	//		S s{3,7};
	//		return s.member();
	//	}
	
	//	constexpr auto x = f();
	public void testNestedMemberFunctionCallsWithImplicitThis() throws Exception {
		assertEvaluationEquals(8);	
	}
	
	//	struct S {
	//		constexpr S(int x, int y):x{x}, y{y*2} {}
	//		constexpr int getY() const {
	//			return y;
	//		}
	//	private:
	//		int x;
	//		int y;
	//	};
	//	
	//	constexpr S s{3, 5};
	//	constexpr int f() { return s.getY(); }
	
	//	constexpr int x = f();
	public void testGlobalMemberFunctionCallFromConstexprFunction() throws Exception {
		assertEvaluationEquals(10);
	}
	
	//	struct S {
	//		constexpr S(int x, int y):x{x}, y{y*2} {}
	//		constexpr int getY() const {
	//			return y;
	//		}
	//	private:
	//		int x;
	//		int y;
	//	};	
	//	constexpr S s{3, 5};
	
	//	constexpr int x = s.getY();
	public void testGlobalMemberFunctionCallFromGlobalConstexpr() throws Exception {
		assertEvaluationEquals(10);
	}
	
	//	struct S {
	//		constexpr S(int x, int y):x{x}, y{y} {}
	//		constexpr int add(S const& other) const {
	//			return y + other.x * 2;
	//		}
	//	private:
	//		int x, y;
	//	};
	//
	//	constexpr int f() {
	//		S s1{2, 5};
	//		S s2{5, 4};
	//      return s1.add(s2);
	//	}

	//	constexpr int x = f();
	public void testManualAddMemberFunction() throws Exception {
	  assertEvaluationEquals(15);
	}
}

Back to the top