Debian Codegraph @

libgomp/testsuite/libgomp.c++/static-aggr-constructor-destructor-3.C

raw
1 // { dg-do run }
2
3 #include <cassert>
4
5 #pragma omp declare target
6
7 struct item {
8 item(item *p, int v) : prev(p), val(v) { }
9 int get() { return prev ? prev->get() * val : val; }
10 item *prev;
11 int val;
12 };
13
14 /* This case demonstrates why constructing on the host and then copying to
15 the target would be less desirable. With on-target construction, "prev"
16 for each 'item' will be a device pointer, not a host pointer. */
17 item hubert1(nullptr, 3);
18 item hubert2(&hubert1, 5);
19 item hubert3(&hubert2, 7);
20 item hubert4(&hubert3, 11);
21
22 #pragma omp end declare target
23
24 int main()
25 {
26 int res = -1;
27
28 #pragma omp target map(from:res)
29 {
30 res = hubert4.get ();
31 }
32
33 assert (res == 1155);
34
35 return 0;
36 }