Debian Codegraph @

gcc/testsuite/g++.dg/cpp0x/lambda/lambda-nullptr.C

raw
1 // PR c++/54170
2 // { dg-do run { target c++11 } }
3 // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
4
5 #include <cassert>
6
7 struct A;
8 typedef A* ptr;
9 typedef int (A::*pmf) (int);
10 typedef int (A::*pdm);
11
12 int total;
13
14 void add(int n)
15 {
16 total += n;
17 }
18
19 template <typename RType, typename Callable>
20 RType Call(Callable native_func, int arg)
21 {
22 return native_func(arg);
23 }
24
25 template <typename RType>
26 RType do_test(int delta)
27 {
28 return Call<RType>([=](int delta) { add(delta); return nullptr; }, delta);
29 }
30
31 template <typename RType>
32 void test()
33 {
34 total = 0;
35 assert (!do_test<RType>(5));
36 assert (total == 5);
37 assert (!do_test<RType>(20));
38 assert (total == 25);
39 assert (!do_test<RType>(-256));
40 assert (total == -231);
41 }
42
43 int main()
44 {
45 test<ptr>();
46 test<pdm>();
47 test<pmf>();
48 }