Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | /* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify |
Chris Lattner | c17925d | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 2 | */ |
| 3 | /* PR3937 */ |
Argyrios Kyrtzidis | 164fdb6 | 2012-12-14 18:53:47 +0000 | [diff] [blame] | 4 | #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 Smith | 19b02cd | 2012-06-22 23:59:08 +0000 | [diff] [blame] | 7 | #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 Lattner | c17925d | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 9 | |
| 10 | zero() |
| 11 | zero(1); /* expected-error {{too many arguments provided to function-like macro invocation}} */ |
| 12 | zero(1, 2, 3); /* expected-error {{too many arguments provided to function-like macro invocation}} */ |
| 13 | |
| 14 | one() /* ok */ |
| 15 | one(a) |
Richard Trieu | 79b4538 | 2013-07-23 18:01:49 +0000 | [diff] [blame] | 16 | one(a,) /* expected-error {{too many arguments provided to function-like macro invocation}} \ |
| 17 | expected-warning {{empty macro arguments are a C99 feature}}*/ |
Chris Lattner | c17925d | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 18 | one(a, b) /* expected-error {{too many arguments provided to function-like macro invocation}} */ |
| 19 | |
| 20 | two() /* expected-error {{too few arguments provided to function-like macro invocation}} */ |
| 21 | two(a) /* expected-error {{too few arguments provided to function-like macro invocation}} */ |
| 22 | two(a,b) |
Richard Smith | 19b02cd | 2012-06-22 23:59:08 +0000 | [diff] [blame] | 23 | two(a, ) /* expected-warning {{empty macro arguments are a C99 feature}} */ |
Chris Lattner | c17925d | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 24 | two(a,b,c) /* expected-error {{too many arguments provided to function-like macro invocation}} */ |
| 25 | two( |
Richard Smith | 19b02cd | 2012-06-22 23:59:08 +0000 | [diff] [blame] | 26 | , /* expected-warning {{empty macro arguments are a C99 feature}} */ |
| 27 | , /* expected-warning {{empty macro arguments are a C99 feature}} \ |
Chris Lattner | c17925d | 2009-04-18 01:13:56 +0000 | [diff] [blame] | 28 | expected-error {{too many arguments provided to function-like macro invocation}} */ |
Richard Trieu | 79b4538 | 2013-07-23 18:01:49 +0000 | [diff] [blame] | 29 | ) /* expected-warning {{empty macro arguments are a C99 feature}} */ |
Richard Smith | 19b02cd | 2012-06-22 23:59:08 +0000 | [diff] [blame] | 30 | two(,) /* expected-warning 2 {{empty macro arguments are a C99 feature}} */ |
Chris Lattner | 249c38b | 2009-04-19 18:26:34 +0000 | [diff] [blame] | 31 | |
| 32 | |
| 33 | |
Chris Lattner | f4c6874 | 2009-04-20 21:08:10 +0000 | [diff] [blame] | 34 | /* PR4006 & rdar://6807000 */ |
Richard Smith | 19b02cd | 2012-06-22 23:59:08 +0000 | [diff] [blame] | 35 | #define e(...) __VA_ARGS__ /* expected-warning {{variadic macros are a C99 feature}} */ |
Chris Lattner | 249c38b | 2009-04-19 18:26:34 +0000 | [diff] [blame] | 36 | e(x) |
Chris Lattner | f4c6874 | 2009-04-20 21:08:10 +0000 | [diff] [blame] | 37 | e() |
| 38 | |
| 39 | zero_dot() |
Richard Smith | 19b02cd | 2012-06-22 23:59:08 +0000 | [diff] [blame] | 40 | one_dot(x) /* empty ... argument: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */ |
| 41 | one_dot() /* empty first argument, elided ...: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */ |
Chris Lattner | 40493eb | 2009-04-24 07:15:46 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | /* rdar://6816766 - Crash with function-like macro test at end of directive. */ |
| 45 | #define E() (i == 0) |
| 46 | #if E |
| 47 | #endif |
Eli Friedman | 14d3c79 | 2012-11-14 02:18:46 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | /* <rdar://problem/12292192> */ |
| 51 | #define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \ |
| 52 | SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */ |
| 53 | NSAssert(somecond, somedesc) |