gcc/testsuite/g++.dg/ext/varargs1.C
raw| 1 | // Test that passing an object with non-trivial copy constructor and |
| 2 | // destructor is (conditionally) supported and has sensible semantics. |
| 3 | |
| 4 | #include <stdarg.h> |
| 5 | extern "C" void abort(); |
| 6 | |
| 7 | void *as[5]; |
| 8 | int i; |
| 9 | |
| 10 | struct A { |
| 11 | A() { as[i++] = this; } |
| 12 | A(const A& a) { |
| 13 | if (&a != as[i-1]) |
| 14 | abort(); |
| 15 | as[i++] = this; |
| 16 | } |
| 17 | ~A() { |
| 18 | if (this != as[--i]) |
| 19 | abort(); |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | void f(int i, ...) { |
| 24 | va_list ap; |
| 25 | va_start (ap, i); |
| 26 | A ar = va_arg (ap, A); |
| 27 | } |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | f(42,A()); |
| 32 | if (i != 0) |
| 33 | abort(); |
| 34 | } |