xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/variadic-block.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks
2*f4a2713aSLionel Sambuc // expected-no-diagnostics
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc #include <stdarg.h>
5*f4a2713aSLionel Sambuc 
main(int argc,char * argv[])6*f4a2713aSLionel Sambuc int main(int argc, char *argv[]) {
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc     long (^addthem)(const char *, ...) = ^long (const char *format, ...){
9*f4a2713aSLionel Sambuc         va_list argp;
10*f4a2713aSLionel Sambuc         const char *p;
11*f4a2713aSLionel Sambuc         int i;
12*f4a2713aSLionel Sambuc         char c;
13*f4a2713aSLionel Sambuc         double d;
14*f4a2713aSLionel Sambuc         long result = 0;
15*f4a2713aSLionel Sambuc         va_start(argp, format);
16*f4a2713aSLionel Sambuc         for (p = format; *p; p++) switch (*p) {
17*f4a2713aSLionel Sambuc             case 'i':
18*f4a2713aSLionel Sambuc                 i = va_arg(argp, int);
19*f4a2713aSLionel Sambuc                 result += i;
20*f4a2713aSLionel Sambuc                 break;
21*f4a2713aSLionel Sambuc             case 'd':
22*f4a2713aSLionel Sambuc                 d = va_arg(argp, double);
23*f4a2713aSLionel Sambuc                 result += (int)d;
24*f4a2713aSLionel Sambuc                 break;
25*f4a2713aSLionel Sambuc             case 'c':
26*f4a2713aSLionel Sambuc                 c = va_arg(argp, int);
27*f4a2713aSLionel Sambuc                 result += c;
28*f4a2713aSLionel Sambuc                 break;
29*f4a2713aSLionel Sambuc         }
30*f4a2713aSLionel Sambuc         return result;
31*f4a2713aSLionel Sambuc     };
32*f4a2713aSLionel Sambuc     long testresult = addthem("ii", 10, 20);
33*f4a2713aSLionel Sambuc     if (testresult != 30) {
34*f4a2713aSLionel Sambuc         return 1;
35*f4a2713aSLionel Sambuc     }
36*f4a2713aSLionel Sambuc     testresult = addthem("idc", 30, 40.0, 'a');
37*f4a2713aSLionel Sambuc     if (testresult != (70+'a')) {
38*f4a2713aSLionel Sambuc         return 1;
39*f4a2713aSLionel Sambuc     }
40*f4a2713aSLionel Sambuc     return 0;
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
43