macro-reserved.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
  2. #define for 0 // expected-warning {{keyword is hidden by macro definition}}
  3. #define final 1
  4. #define __HAVE_X 0
  5. #define _HAVE_X 0
  6. #define X__Y
  7. #undef for
  8. #undef final
  9. #undef __HAVE_X
  10. #undef _HAVE_X
  11. #undef X__Y
  12. #undef __cplusplus
  13. #define __cplusplus
  14. // whitelisted definitions
  15. #define while while
  16. #define const
  17. #define static
  18. #define extern
  19. #define inline
  20. #undef while
  21. #undef const
  22. #undef static
  23. #undef extern
  24. #undef inline
  25. #define inline __inline
  26. #undef inline
  27. #define inline __inline__
  28. #undef inline
  29. #define inline inline__ // expected-warning {{keyword is hidden by macro definition}}
  30. #undef inline
  31. #define extern __inline // expected-warning {{keyword is hidden by macro definition}}
  32. #undef extern
  33. #define extern __extern // expected-warning {{keyword is hidden by macro definition}}
  34. #undef extern
  35. #define extern __extern__ // expected-warning {{keyword is hidden by macro definition}}
  36. #undef extern
  37. #define inline _inline // expected-warning {{keyword is hidden by macro definition}}
  38. #undef inline
  39. #define volatile // expected-warning {{keyword is hidden by macro definition}}
  40. #undef volatile
  41. #pragma clang diagnostic warning "-Wreserved-id-macro"
  42. #define switch if // expected-warning {{keyword is hidden by macro definition}}
  43. #define final 1
  44. #define __HAVE_X 0 // expected-warning {{macro name is a reserved identifier}}
  45. #define _HAVE_X 0 // expected-warning {{macro name is a reserved identifier}}
  46. #define X__Y // expected-warning {{macro name is a reserved identifier}}
  47. #undef __cplusplus // expected-warning {{macro name is a reserved identifier}}
  48. #undef _HAVE_X // expected-warning {{macro name is a reserved identifier}}
  49. #undef X__Y // expected-warning {{macro name is a reserved identifier}}
  50. int x;