macro_fn.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* RUN: %clang_cc1 %s -Eonly -std=c89 -pedantic -verify
  2. */
  3. /* PR3937 */
  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}} */
  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}} */
  9. zero()
  10. zero(1); /* expected-error {{too many arguments provided to function-like macro invocation}} */
  11. zero(1, 2, 3); /* expected-error {{too many arguments provided to function-like macro invocation}} */
  12. one() /* ok */
  13. one(a)
  14. one(a,) /* expected-error {{too many arguments provided to function-like macro invocation}} \
  15. expected-warning {{empty macro arguments are a C99 feature}}*/
  16. one(a, b) /* expected-error {{too many arguments provided to function-like macro invocation}} */
  17. two() /* expected-error {{too few arguments provided to function-like macro invocation}} */
  18. two(a) /* expected-error {{too few arguments provided to function-like macro invocation}} */
  19. two(a,b)
  20. two(a, ) /* expected-warning {{empty macro arguments are a C99 feature}} */
  21. two(a,b,c) /* expected-error {{too many arguments provided to function-like macro invocation}} */
  22. two(
  23. , /* expected-warning {{empty macro arguments are a C99 feature}} */
  24. , /* expected-warning {{empty macro arguments are a C99 feature}} \
  25. expected-error {{too many arguments provided to function-like macro invocation}} */
  26. ) /* expected-warning {{empty macro arguments are a C99 feature}} */
  27. two(,) /* expected-warning 2 {{empty macro arguments are a C99 feature}} */
  28. /* PR4006 & rdar://6807000 */
  29. #define e(...) __VA_ARGS__ /* expected-warning {{variadic macros are a C99 feature}} */
  30. e(x)
  31. e()
  32. zero_dot()
  33. one_dot(x) /* empty ... argument: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */
  34. one_dot() /* empty first argument, elided ...: expected-warning {{must specify at least one argument for '...' parameter of variadic macro}} */
  35. /* rdar://6816766 - Crash with function-like macro test at end of directive. */
  36. #define E() (i == 0)
  37. #if E
  38. #endif
  39. /* <rdar://problem/12292192> */
  40. #define NSAssert(condition, desc, ...) /* expected-warning {{variadic macros are a C99 feature}} */ \
  41. SomeComplicatedStuff((desc), ##__VA_ARGS__) /* expected-warning {{token pasting of ',' and __VA_ARGS__ is a GNU extension}} */
  42. NSAssert(somecond, somedesc)