summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv13.C
blob: 159c4ccd5258d7d35aa4c72f9502bc2387b27a32 (plain)
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
// PR c++/86943
// { dg-do run { target c++14 } }

int c[3];

struct S
{
  S () : s (1234) { c[0]++; }
  S (const S &) { __builtin_abort (); }
  S (S &&x) noexcept { if (x.s != 1234) __builtin_abort (); s = 1234; x.s = 2345; c[1]++; }
  ~S () { if (s != 1234 && s != 2345) __builtin_abort (); c[2]++; }
  int s;
};

using F = S (*) (S);

F
foo ()
{
  return [] (auto val)->S { if (val.s != 1234) __builtin_abort (); return {}; };
}

int
main ()
{
  {
    volatile F f = foo ();
    S s = f ({});
    if (s.s != 1234) __builtin_abort ();
  }
  if (c[0] + c[1] != c[2])
    __builtin_abort ();
}