File: n3363.c

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (40 lines) | stat: -rw-r--r-- 2,100 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// RUN: %clang_cc1 -triple x86_64-pc-linux -verify=expected,array-type -std=c2y -Wall -pedantic -ffreestanding %s
// RUN: %clang_cc1 -triple aarch64-pc-win32 -verify=expected,char-ptr-type -std=c2y -Wall -pedantic -ffreestanding %s

/* WG14 N3363: Clang 5
 * stdarg.h wording... v3
 *
 * Clarifies that va_start can only be used within a function body, and that
 * the macros and functions require an lvalue of type va_list instead of an
 * rvalue.
 *
 * Clang has diagnosed this correctly in all cases except va_copy since
 * Clang 5. va_copy still needs to be updated to issue a diagnostic about use
 * of an rvalue. However, our lack of a diagnostic is still conforming because
 * a diagnostic is not required (it's not a constraint violation).
 */

#include <stdarg.h>

// The va_list argument given to every macro defined in this subclause shall be
// an lvalue of this type or the result of array-to-pointer decay of such an
// lvalue.
void f(int a, ...) {
  va_list rvalue(); // array-type-error {{function cannot return array type 'va_list' (aka '__builtin_va_list')}}
  va_start(rvalue()); // / char-ptr-type-error {{non-const lvalue reference to type '__builtin_va_list' cannot bind to a temporary of type 'va_list' (aka 'char *')}}
  va_arg(rvalue(), int); // char-ptr-type-error {{expression is not assignable}}
  // FIXME: this should get two diagnostics about use of a non-lvalue.
  va_copy(rvalue(), rvalue()); // char-ptr-type-error {{non-const lvalue reference to type '__builtin_va_list' cannot bind to a temporary of type 'va_list' (aka 'char *')}}
  va_end(rvalue()); // char-ptr-type-error {{non-const lvalue reference to type '__builtin_va_list' cannot bind to a temporary of type 'va_list' (aka 'char *')}}
}

// The va_start macro may only be invoked in the compound-statement of the body
// of a variadic function.
void g(va_list ap, int [(va_start(ap), 1)], ...) { // expected-error {{'va_start' cannot be used outside a function}}
  va_end(ap);
}

va_list ap;
struct S {
  int array[(va_start(ap), 1)]; // expected-error {{'va_start' cannot be used outside a function}}
};