18c1441f8SAlexey Samsonov //
2*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
4*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
58c1441f8SAlexey Samsonov
68c1441f8SAlexey Samsonov // -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil; -*-
78c1441f8SAlexey Samsonov // 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
88c1441f8SAlexey Samsonov // CONFIG 27: error:
98c1441f8SAlexey Samsonov
108c1441f8SAlexey Samsonov #import <stdio.h>
118c1441f8SAlexey Samsonov #import <stdlib.h>
128c1441f8SAlexey Samsonov #import <string.h>
138c1441f8SAlexey Samsonov #import <stdarg.h>
148c1441f8SAlexey Samsonov
158c1441f8SAlexey Samsonov
main(int argc,const char * argv[])168c1441f8SAlexey Samsonov int main (int argc, const char * argv[]) {
178c1441f8SAlexey Samsonov int (^sumn)(int n, ...);
188c1441f8SAlexey Samsonov int six = 0;
198c1441f8SAlexey Samsonov
208c1441f8SAlexey Samsonov sumn = ^(int a, int b, int n, ...){
218c1441f8SAlexey Samsonov int result = 0;
228c1441f8SAlexey Samsonov va_list numbers;
238c1441f8SAlexey Samsonov int i;
248c1441f8SAlexey Samsonov
258c1441f8SAlexey Samsonov va_start(numbers, n);
268c1441f8SAlexey Samsonov for (i = 0 ; i < n ; i++) {
278c1441f8SAlexey Samsonov result += va_arg(numbers, int);
288c1441f8SAlexey Samsonov }
298c1441f8SAlexey Samsonov va_end(numbers);
308c1441f8SAlexey Samsonov
318c1441f8SAlexey Samsonov return result;
328c1441f8SAlexey Samsonov };
338c1441f8SAlexey Samsonov
348c1441f8SAlexey Samsonov six = sumn(3, 1, 2, 3);
358c1441f8SAlexey Samsonov
368c1441f8SAlexey Samsonov if ( six != 6 ) {
378c1441f8SAlexey Samsonov printf("%s: Expected 6 but got %d\n", argv[0], six);
388c1441f8SAlexey Samsonov exit(1);
398c1441f8SAlexey Samsonov }
408c1441f8SAlexey Samsonov
418c1441f8SAlexey Samsonov printf("%s: success\n", argv[0]);
428c1441f8SAlexey Samsonov return 0;
438c1441f8SAlexey Samsonov }
44