File: macro_fn.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (52 lines) | stat: -rw-r--r-- 2,587 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
41
42
43
44
45
46
47
48
49
50
51
52
/* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
*/
/* PR3937 */
#define zero() 0 /* expected-note 2 {{defined here}} */
#define one(x) 0 /* expected-note 2 {{defined here}} */
#define two(x, y) 0 /* expected-note 4 {{defined here}} */
#define zero_dot(...) 0   /* expected-warning {{variadic macros are a C99 feature}} */
#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */

zero()
zero(1);          /* expected-error {{too many arguments provided to function-like macro invocation}} */
zero(1, 2, 3);    /* expected-error {{too many arguments provided to function-like macro invocation}} */

one()   /* ok */
one(a)
one(a,)           /* expected-error {{too many arguments provided to function-like macro invocation}} \
                     expected-warning {{empty macro arguments are a C99 feature}}*/
one(a, b)         /* expected-error {{too many arguments provided to function-like macro invocation}} */

two()       /* expected-error {{too few arguments provided to function-like macro invocation}} */
two(a)      /* expected-error {{too few arguments provided to function-like macro invocation}} */
two(a,b)
two(a, )    /* expected-warning {{empty macro arguments are a C99 feature}} */
two(a,b,c)  /* expected-error {{too many arguments provided to function-like macro invocation}} */
two(
    ,     /* expected-warning {{empty macro arguments are a C99 feature}} */
    ,     /* expected-warning {{empty macro arguments are a C99 feature}}  \
             expected-error {{too many arguments provided to function-like macro invocation}} */
    )     /* expected-warning {{empty macro arguments are a C99 feature}} */
two(,)      /* expected-warning 2 {{empty macro arguments are a C99 feature}} */



/* PR4006 */
#define e(...) __VA_ARGS__  /* expected-warning {{variadic macros are a C99 feature}} */
e(x)
e()

zero_dot()
one_dot(x)  /* empty ... argument: expected-warning {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}}  */
one_dot()   /* empty first argument, elided ...: expected-warning {{passing no argument for the '...' parameter of a variadic macro is a C23 extension}} */


/* Crash with function-like macro test at end of directive. */
#define E() (i == 0)
#if E
#endif


#define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
    SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
NSAssert(somecond, somedesc)