xref: /minix3/external/bsd/llvm/dist/clang/test/Preprocessor/macro_fn.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc /* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
2*f4a2713aSLionel Sambuc */
3*f4a2713aSLionel Sambuc /* PR3937 */
4*f4a2713aSLionel Sambuc #define zero() 0 /* expected-note 2 {{defined here}} */
5*f4a2713aSLionel Sambuc #define one(x) 0 /* expected-note 2 {{defined here}} */
6*f4a2713aSLionel Sambuc #define two(x, y) 0 /* expected-note 4 {{defined here}} */
7*f4a2713aSLionel Sambuc #define zero_dot(...) 0   /* expected-warning {{variadic macros are a C99 feature}} */
8*f4a2713aSLionel Sambuc #define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc zero()
11*f4a2713aSLionel Sambuc zero(1);          /* expected-error {{too many arguments provided to function-like macro invocation}} */
12*f4a2713aSLionel Sambuc zero(1, 2, 3);    /* expected-error {{too many arguments provided to function-like macro invocation}} */
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc one()   /* ok */
15*f4a2713aSLionel Sambuc one(a)
16*f4a2713aSLionel Sambuc one(a,)           /* expected-error {{too many arguments provided to function-like macro invocation}} \
17*f4a2713aSLionel Sambuc                      expected-warning {{empty macro arguments are a C99 feature}}*/
18*f4a2713aSLionel Sambuc one(a, b)         /* expected-error {{too many arguments provided to function-like macro invocation}} */
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc two()       /* expected-error {{too few arguments provided to function-like macro invocation}} */
21*f4a2713aSLionel Sambuc two(a)      /* expected-error {{too few arguments provided to function-like macro invocation}} */
22*f4a2713aSLionel Sambuc two(a,b)
23*f4a2713aSLionel Sambuc two(a, )    /* expected-warning {{empty macro arguments are a C99 feature}} */
24*f4a2713aSLionel Sambuc two(a,b,c)  /* expected-error {{too many arguments provided to function-like macro invocation}} */
25*f4a2713aSLionel Sambuc two(
26*f4a2713aSLionel Sambuc     ,     /* expected-warning {{empty macro arguments are a C99 feature}} */
27*f4a2713aSLionel Sambuc     ,     /* expected-warning {{empty macro arguments are a C99 feature}}  \
28*f4a2713aSLionel Sambuc              expected-error {{too many arguments provided to function-like macro invocation}} */
29*f4a2713aSLionel Sambuc     )     /* expected-warning {{empty macro arguments are a C99 feature}} */
30*f4a2713aSLionel Sambuc two(,)      /* expected-warning 2 {{empty macro arguments are a C99 feature}} */
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc /* PR4006 & rdar://6807000 */
35*f4a2713aSLionel Sambuc #define e(...) __VA_ARGS__  /* expected-warning {{variadic macros are a C99 feature}} */
36*f4a2713aSLionel Sambuc e(x)
37*f4a2713aSLionel Sambuc e()
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc zero_dot()
40*f4a2713aSLionel Sambuc one_dot(x)  /* empty ... argument: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}}  */
41*f4a2713aSLionel Sambuc one_dot()   /* empty first argument, elided ...: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc /* rdar://6816766 - Crash with function-like macro test at end of directive. */
45*f4a2713aSLionel Sambuc #define E() (i == 0)
46*f4a2713aSLionel Sambuc #if E
47*f4a2713aSLionel Sambuc #endif
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc /* <rdar://problem/12292192> */
51*f4a2713aSLionel Sambuc #define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
52*f4a2713aSLionel Sambuc     SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
53*f4a2713aSLionel Sambuc NSAssert(somecond, somedesc)
54