1 // Ensure that generic lambdas properly construct and destroy user types.
2 // { dg-options "-DUSE_AUTO_SYNTAX" }
3 // { dg-do run { target c++14 } }
11 S (S&& old) { old.shadow = true; i += 2; }
12 ~S () { if (shadow) i -= 2; else --i; }
17 extern "C" int printf(const char*, ...);
18 #define assert(e) if (e); else \
19 printf ("%s:%d: !(%s)\n", __FILE__, __LINE__, #e), __builtin_abort ();
28 auto byref = [] (auto& r) { (void) r; };
29 auto bycref = [] (auto const& r) { (void) r; };
30 auto byval = [] (auto v, auto const x) { assert (i == x); (void) v; };
31 auto byrval = [] (auto&& r, auto const x) { S steal (static_cast<S&&>(r));
34 #elif USE_EXPLICIT_TEMPLATE_SYNTAX
35 auto byref = [] <typename T> (T& r) { (void) r; };
36 auto bycref = [] <typename T> (T const& r) { (void) r; };
37 auto byval = [] <typename T, typename I>
38 (T v, I const x) { assert (i == x); (void) v; };
39 auto byrval = [] <typename T, typename I>
40 (T&& r, I const x) { S steal (static_cast<S&&>(r));
44 byref (s); assert (i == 4);
45 bycref (s); assert (i == 4);
46 byval (s, 5); assert (i == 4);
47 byrval (static_cast<S&&>(s), 6); assert (i == 5);