1//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6// -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil; -*-
7// HACK ALERT: gcc and g++ give different errors, referencing the line number to ensure that it checks for the right error; MUST KEEP IN SYNC WITH THE TEST
8// CONFIG 27: error:
9
10#import <stdio.h>
11#import <stdlib.h>
12#import <string.h>
13#import <stdarg.h>
14
15
16int main (int argc, const char * argv[]) {
17 int (^sumn)(int n, ...);
18 int six = 0;
19
20 sumn = ^(int a, int b, int n, ...){
21 int result = 0;
22 va_list numbers;
23 int i;
24
25 va_start(numbers, n);
26 for (i = 0 ; i < n ; i++) {
27 result += va_arg(numbers, int);
28 }
29 va_end(numbers);
30
31 return result;
32 };
33
34 six = sumn(3, 1, 2, 3);
35
36 if ( six != 6 ) {
37 printf("%s: Expected 6 but got %d\n", argv[0], six);
38 exit(1);
39 }
40
41 printf("%s: success\n", argv[0]);
42 return 0;
43}
44