You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This builtin is supported by GCC and is a way to improve diagnostic
behavior for va_start in C23 mode. C23 no longer requires a second
argument to the va_start macro in support of variadic functions with no
leading parameters. However, we still want to diagnose passing more than
two arguments, or diagnose when passing something other than the last
parameter in the variadic function.
This also updates the freestanding <stdarg.h> header to use the new
builtin, same as how GCC works.
Fixes#124031
Copy file name to clipboardExpand all lines: clang/test/C/C23/n2975.c
+5-18
Original file line number
Diff line number
Diff line change
@@ -6,28 +6,21 @@
6
6
7
7
#include <stdarg.h>
8
8
9
-
#define DERP this is an error
10
-
11
9
void func(...) { // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}}
12
10
// Show that va_start doesn't require the second argument in C23 mode.
13
11
va_list list;
14
-
va_start(list); // expected-warning {{passing no argument for the '...' parameter of a variadic macro is incompatible with C standards before C23}} expected-note@* {{macro 'va_start' defined here}}
15
-
va_end(list);
16
-
17
-
// Show that va_start doesn't expand or evaluate the second argument.
18
-
va_start(list, DERP);
12
+
va_start(list); // expected-warning {{passing only one argument to 'va_start' is incompatible with C standards before C23}}
19
13
va_end(list);
20
14
21
-
// FIXME: it would be kinder to diagnose this instead of silently accepting it.
22
-
va_start(list, 1, 2);
15
+
va_start(list, 1, 2); // expected-error {{too many arguments to function call, expected at most 2, have 3}}
23
16
va_end(list);
24
17
25
18
// We didn't change the behavior of __builtin_va_start (and neither did GCC).
26
19
__builtin_va_start(list); // expected-error {{too few arguments to function call, expected 2, have 1}}
27
20
28
21
// 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), ""); // expected-warning {{passing no argument for the '...' parameter of a variadic macro is incompatible with C standards before C23}} expected-note@* {{macro 'va_start' defined here}}
_Static_assert(__builtin_types_compatible_p(__typeof__(va_start(list)), void), ""); // expected-warning {{passing only one argument to 'va_start' is incompatible with C standards before C23}}
23
+
_Static_assert(__builtin_types_compatible_p(__typeof__(__builtin_va_start(list, 0)), void), ""); // expected-warning {{passing only one argument to 'va_start' is incompatible with C standards before C23}}
31
24
}
32
25
33
26
// Show that function pointer types also don't need an argument before the
@@ -37,13 +30,7 @@ typedef void (*fp)(...); // expected-warning {{'...' as the only parameter of a
37
30
// Passing something other than the argument before the ... is still not valid.
38
31
void diag(int a, int b, ...) {
39
32
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 C23 and later we've lost the
45
-
// diagnostic entirely. GCC has the same issue currently.
46
-
va_start(list, a);
33
+
va_start(list, a); // expected-warning {{second argument to 'va_start' is not the last non-variadic parameter}}
47
34
// However, the builtin itself is under no such constraints regarding
48
35
// expanding or evaluating the second argument, so it can still diagnose.
49
36
__builtin_va_start(list, a); // expected-warning {{second argument to 'va_start' is not the last non-variadic parameter}}
0 commit comments