brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · 854afef Raw
66 lines · c
1// RUN: %clang_cc1 -verify -ffreestanding -Wpre-c2x-compat -std=c2x %s2 3/* WG14 N2975: partial4 * Relax requirements for va_start5 */6 7#include <stdarg.h>8 9void func(...) { // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}}10  // Show that va_start doesn't require the second argument in C23 mode.11  va_list list;12  va_start(list); // expected-warning {{passing only one argument to 'va_start' is incompatible with C standards before C23}}13  va_end(list);14 15  va_start(list, 1, 2); // expected-error {{too many arguments to function call, expected at most 2, have 3}}16  va_end(list);17 18  // We didn't change the behavior of __builtin_va_start (and neither did GCC).19  __builtin_va_start(list); // expected-error {{too few arguments to function call, expected 2, have 1}}20 21  // Verify that the return type of a call to va_start is 'void'.22  _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}}24}25 26// Show that function pointer types also don't need an argument before the27// ellipsis.28typedef void (*fp)(...); // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}}29 30// Passing something other than the argument before the ... is still not valid.31void diag(int a, int b, ...) {32  va_list list;33  va_start(list, a); // expected-warning {{second argument to 'va_start' is not the last non-variadic parameter}}34  // However, the builtin itself is under no such constraints regarding35  // expanding or evaluating the second argument, so it can still diagnose.36  __builtin_va_start(list, a); // expected-warning {{second argument to 'va_start' is not the last non-variadic parameter}}37  va_end(list);38}39 40void foo(int a...); // expected-error {{C requires a comma prior to the ellipsis in a variadic function type}}41 42void use(void) {43  // Demonstrate that we can actually call the variadic function when it has no44  // formal parameters.45  func(1, '2', 3.0, "4");46  func();47 48  // And that assignment still works as expected.49  fp local = func;50 51  // ...including conversion errors.52  fp other_local = diag; // expected-error {{incompatible function pointer types initializing 'fp' (aka 'void (*)(...)') with an expression of type 'void (int, int, ...)'}}53}54 55// int(...) not parsed as variadic function type.56// https://github.com/llvm/llvm-project/issues/14525057int va_fn(...);  // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}}58 59// As typeof() argument60typeof(int(...))*fn_ptr = &va_fn;  // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}} \61                                   // expected-warning {{'typeof' is incompatible with C standards before C23}}62 63// As _Generic association type64int i = _Generic(typeof(va_fn), int(...):1);  // expected-warning {{'...' as the only parameter of a function is incompatible with C standards before C23}} \65                                              // expected-warning {{'typeof' is incompatible with C standards before C23}}66