[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / C / C2x / n2975.c
blobf5b94c256d00f6d7d2bb99c47574fe0f290ced3e
1 // RUN: %clang_cc1 -verify -ffreestanding -Wpre-c2x-compat -std=c2x %s
3 /* WG14 N2975: partial
4 * Relax requirements for va_start
5 */
7 #include <stdarg.h>
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.
13 va_list list;
14 va_start(list); // FIXME: it would be nice to issue a portability warning to C17 and earlier here.
15 va_end(list);
17 // Show that va_start doesn't expand or evaluate the second argument.
18 va_start(list, DERP);
19 va_end(list);
21 // FIXME: it would be kinder to diagnose this instead of silently accepting it.
22 va_start(list, 1, 2);
23 va_end(list);
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
34 // ellipsis.
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, ...) {
39 va_list list;
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.
46 va_start(list, a);
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}}
50 va_end(list);
53 void foo(int a...); // expected-error {{C requires a comma prior to the ellipsis in a variadic function type}}
55 void use(void) {
56 // Demonstrate that we can actually call the variadic function when it has no
57 // formal parameters.
58 func(1, '2', 3.0, "4");
59 func();
61 // And that assignment still works as expected.
62 fp local = func;
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, ...)'}}