blob: fcdb90ad57d649470e4e3695f3268f77b0eb5697 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001/* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
Chris Lattner0a4f1b92009-04-18 01:13:56 +00002*/
3/* PR3937 */
Argyrios Kyrtzidis0ee8de72012-12-14 18:53:47 +00004#define zero() 0 /* expected-note 2 {{defined here}} */
5#define one(x) 0 /* expected-note 2 {{defined here}} */
6#define two(x, y) 0 /* expected-note 4 {{defined here}} */
Richard Smith9f728cd2012-06-22 23:59:08 +00007#define zero_dot(...) 0 /* expected-warning {{variadic macros are a C99 feature}} */
8#define one_dot(x, ...) 0 /* expected-warning {{variadic macros are a C99 feature}} expected-note 2{{macro 'one_dot' defined here}} */
Chris Lattner0a4f1b92009-04-18 01:13:56 +00009
10zero()
11zero(1); /* expected-error {{too many arguments provided to function-like macro invocation}} */
12zero(1, 2, 3); /* expected-error {{too many arguments provided to function-like macro invocation}} */
13
14one() /* ok */
15one(a)
16one(a,) /* expected-error {{too many arguments provided to function-like macro invocation}} */
17one(a, b) /* expected-error {{too many arguments provided to function-like macro invocation}} */
18
19two() /* expected-error {{too few arguments provided to function-like macro invocation}} */
20two(a) /* expected-error {{too few arguments provided to function-like macro invocation}} */
21two(a,b)
Richard Smith9f728cd2012-06-22 23:59:08 +000022two(a, ) /* expected-warning {{empty macro arguments are a C99 feature}} */
Chris Lattner0a4f1b92009-04-18 01:13:56 +000023two(a,b,c) /* expected-error {{too many arguments provided to function-like macro invocation}} */
24two(
Richard Smith9f728cd2012-06-22 23:59:08 +000025 , /* expected-warning {{empty macro arguments are a C99 feature}} */
26 , /* expected-warning {{empty macro arguments are a C99 feature}} \
Chris Lattner0a4f1b92009-04-18 01:13:56 +000027 expected-error {{too many arguments provided to function-like macro invocation}} */
28 )
Richard Smith9f728cd2012-06-22 23:59:08 +000029two(,) /* expected-warning 2 {{empty macro arguments are a C99 feature}} */
Chris Lattner8fde5972009-04-19 18:26:34 +000030
31
32
Chris Lattner97e2de12009-04-20 21:08:10 +000033/* PR4006 & rdar://6807000 */
Richard Smith9f728cd2012-06-22 23:59:08 +000034#define e(...) __VA_ARGS__ /* expected-warning {{variadic macros are a C99 feature}} */
Chris Lattner8fde5972009-04-19 18:26:34 +000035e(x)
Chris Lattner97e2de12009-04-20 21:08:10 +000036e()
37
38zero_dot()
Richard Smith9f728cd2012-06-22 23:59:08 +000039one_dot(x) /* empty ... argument: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */
40one_dot() /* empty first argument, elided ...: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */
Chris Lattnera864cf72009-04-24 07:15:46 +000041
42
43/* rdar://6816766 - Crash with function-like macro test at end of directive. */
44#define E() (i == 0)
45#if E
46#endif
Eli Friedman4fa4b482012-11-14 02:18:46 +000047
48
49/* <rdar://problem/12292192> */
50#define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
51 SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
52NSAssert(somecond, somedesc)