Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks |
Steve Naroff | cd9c514 | 2009-04-15 19:33:47 +0000 | [diff] [blame] | 2 | |
| 3 | #include <stdarg.h> |
| 4 | |
| 5 | int main(int argc, char *argv[]) { |
| 6 | |
| 7 | long (^addthem)(const char *, ...) = ^long (const char *format, ...){ |
| 8 | va_list argp; |
| 9 | const char *p; |
| 10 | int i; |
| 11 | char c; |
| 12 | double d; |
| 13 | long result = 0; |
| 14 | va_start(argp, format); |
| 15 | for (p = format; *p; p++) switch (*p) { |
| 16 | case 'i': |
| 17 | i = va_arg(argp, int); |
| 18 | result += i; |
| 19 | break; |
| 20 | case 'd': |
| 21 | d = va_arg(argp, double); |
| 22 | result += (int)d; |
| 23 | break; |
| 24 | case 'c': |
| 25 | c = va_arg(argp, int); |
| 26 | result += c; |
| 27 | break; |
| 28 | } |
| 29 | return result; |
| 30 | }; |
| 31 | long testresult = addthem("ii", 10, 20); |
| 32 | if (testresult != 30) { |
| 33 | return 1; |
| 34 | } |
| 35 | testresult = addthem("idc", 30, 40.0, 'a'); |
| 36 | if (testresult != (70+'a')) { |
| 37 | return 1; |
| 38 | } |
| 39 | return 0; |
| 40 | } |
| 41 | |