44 lines · c
1// RUN: %clang_cc1 -std=c23 -fsyntax-only -ffreestanding -verify=expected,both %s -triple i386-pc-unknown2// RUN: %clang_cc1 -std=c23 -fsyntax-only -ffreestanding -verify=expected,both %s -triple x86_64-apple-darwin93// RUN: %clang_cc1 -std=c23 -fsyntax-only -ffreestanding -fms-compatibility -verify=expected,both %s -triple x86_64-pc-win324// RUN: %clang_cc1 -std=c17 -fsyntax-only -ffreestanding -verify=both,pre-c23 %s5 6void foo(int x, int y, ...) {7 __builtin_va_list list;8 __builtin_c23_va_start(); // pre-c23-error {{use of unknown builtin '__builtin_c23_va_start'}} \9 expected-error{{too few arguments to function call, expected 1, have 0}}10 // Note, the unknown builtin diagnostic is only issued once per function,11 // which is why the rest of the lines do not get the same diagonstic.12 __builtin_c23_va_start(list); // ok13 __builtin_c23_va_start(list, 0); // expected-warning {{second argument to 'va_start' is not the last non-variadic parameter}}14 __builtin_c23_va_start(list, x); // expected-warning {{second argument to 'va_start' is not the last non-variadic parameter}}15 __builtin_c23_va_start(list, y); // ok16 __builtin_c23_va_start(list, 0, 1); // expected-error {{too many arguments to function call, expected at most 2, have 3}}17 __builtin_c23_va_start(list, y, y); // expected-error {{too many arguments to function call, expected at most 2, have 3}}18}19 20// Test the same thing as above, only with the macro from stdarg.h. This will21// not have the unknown builtin diagnostics, but will have different22// diagnostics between C23 and earlier modes.23#include <stdarg.h>24void bar(int x, int y, ...) {25 // FIXME: the "use of undeclared identifier 'va_start'" diagnostics is an odd26 // follow-on diagnostic that should be silenced.27 va_list list;28 va_start(); // pre-c23-error {{too few arguments provided to function-like macro invocation}} \29 pre-c23-error {{use of undeclared identifier 'va_start'}} \30 expected-error{{too few arguments to function call, expected 1, have 0}}31 va_start(list); // pre-c23-error {{too few arguments provided to function-like macro invocation}} \32 pre-c23-error {{use of undeclared identifier 'va_start'}}33 va_start(list, 0); // both-warning {{second argument to 'va_start' is not the last non-variadic parameter}}34 va_start(list, x); // both-warning {{second argument to 'va_start' is not the last non-variadic parameter}}35 va_start(list, y); // ok36 va_start(list, 0, 1); // pre-c23-error {{too many arguments provided to function-like macro invocation}} \37 pre-c23-error {{use of undeclared identifier 'va_start'}} \38 expected-error {{too many arguments to function call, expected at most 2, have 3}}39 va_start(list, y, y); // pre-c23-error {{too many arguments provided to function-like macro invocation}} \40 pre-c23-error {{use of undeclared identifier 'va_start'}} \41 expected-error {{too many arguments to function call, expected at most 2, have 3}} 42 // pre-c23-note@__stdarg_va_arg.h:* 4 {{macro 'va_start' defined here}}43}44