Skip to content

Commit 4053449

Browse files
committed
Add constexpr tests
1 parent d046919 commit 4053449

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

clang/test/SemaCXX/builtin-invoke.cpp

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ namespace std {
3434
T* ptr;
3535

3636
public:
37-
reference_wrapper(T& ref) : ptr(&ref) {}
37+
constexpr reference_wrapper(T& ref) : ptr(&ref) {}
3838

39-
T& get() { return *ptr; }
39+
constexpr T& get() { return *ptr; }
4040
};
4141

4242
template <class T>
43-
reference_wrapper<T> ref(T& v) {
43+
constexpr reference_wrapper<T> ref(T& v) {
4444
return reference_wrapper<T>(v);
4545
}
4646
} // namespace std
@@ -190,3 +190,42 @@ void call3() {
190190
func(d, &DependentTest::func);
191191
func(d, &DependentTest::bad_func); // expected-note {{requested here}}
192192
}
193+
194+
constexpr int constexpr_func() {
195+
return 42;
196+
}
197+
198+
struct ConstexprTestStruct {
199+
int i;
200+
constexpr int func() {
201+
return 55;
202+
}
203+
};
204+
205+
// Make sure that constant evaluation works
206+
static_assert([]() {
207+
208+
ConstexprTestStruct s;
209+
if (__builtin_invoke(&ConstexprTestStruct::func, s) != 55) // [func.requires]/p1.1
210+
return false;
211+
if (__builtin_invoke(&ConstexprTestStruct::func, std::ref(s)) != 55) // [func.requires]/p1.2
212+
return false;
213+
if (__builtin_invoke(&ConstexprTestStruct::func, &s) != 55) // [func.requires]/p1.3
214+
return false;
215+
216+
s.i = 22;
217+
if (__builtin_invoke(&ConstexprTestStruct::i, s) != 22) // [func.requires]/p1.4
218+
return false;
219+
if (__builtin_invoke(&ConstexprTestStruct::i, std::ref(s)) != 22) // [func.requires]/p1.5
220+
return false;
221+
if (__builtin_invoke(&ConstexprTestStruct::i, &s) != 22) // [func.requires]/p1.6
222+
return false;
223+
224+
// [func.requires]/p1.7
225+
if (__builtin_invoke(constexpr_func) != 42)
226+
return false;
227+
if (__builtin_invoke([] { return 34; }) != 34)
228+
return false;
229+
230+
return true;
231+
}());

0 commit comments

Comments
 (0)