1 // RUN: %clang_cc1 -verify -ffreestanding -Wpre-c2x-compat -std=c2x %s
4 * Relax requirements for va_start
9 #define DERP this is an error
11 void func(...) { // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C2x}}
12 // Show that va_start doesn't require the second argument in C2x mode.
14 va_start(list
); // FIXME: it would be nice to issue a portability warning to C17 and earlier here.
17 // Show that va_start doesn't expand or evaluate the second argument.
21 // FIXME: it would be kinder to diagnose this instead of silently accepting it.
25 // We didn't change the behavior of __builtin_va_start (and neither did GCC).
26 __builtin_va_start(list
); // expected-error {{too few arguments to function call, expected 2, have 1}}
28 // Verify that the return type of a call to va_start is 'void'.
29 _Static_assert(__builtin_types_compatible_p(__typeof__(va_start(list
)), void), "");
30 _Static_assert(__builtin_types_compatible_p(__typeof__(__builtin_va_start(list
, 0)), void), "");
33 // Show that function pointer types also don't need an argument before the
35 typedef void (*fp
)(...); // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C2x}}
37 // Passing something other than the argument before the ... is still not valid.
38 void diag(int a
, int b
, ...) {
40 // FIXME: the call to va_start should also diagnose the same way as the call
41 // to __builtin_va_start. However, because va_start is not allowed to expand
42 // or evaluate the second argument, we can't pass it along to
43 // __builtin_va_start to get that diagnostic. So in C17 and earlier, we will
44 // diagnose this use through the macro, but in C2x and later we've lost the
45 // diagnostic entirely. GCC has the same issue currently.
47 // However, the builtin itself is under no such constraints regarding
48 // expanding or evaluating the second argument, so it can still diagnose.
49 __builtin_va_start(list
, a
); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
53 void foo(int a
...); // expected-error {{C requires a comma prior to the ellipsis in a variadic function type}}
56 // Demonstrate that we can actually call the variadic function when it has no
58 func(1, '2', 3.0, "4");
61 // And that assignment still works as expected.
64 // ...including conversion errors.
65 fp other_local
= diag
; // expected-error {{incompatible function pointer types initializing 'fp' (aka 'void (*)(...)') with an expression of type 'void (int, int, ...)'}}