format-strings-enum.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -verify %s
  2. // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x c++ -verify %s
  3. // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x c++ -std=c++11 -verify %s
  4. // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c -verify %s
  5. // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c++ -std=c++11 -verify %s
  6. #ifdef __cplusplus
  7. # define EXTERN_C extern "C"
  8. #else
  9. # define EXTERN_C extern
  10. #endif
  11. EXTERN_C int printf(const char *,...);
  12. typedef enum { Constant = 0 } TestEnum;
  13. // Note that in C, the type of 'Constant' is 'int'. In C++ it is 'TestEnum'.
  14. // This is why we don't check for that in the expected output.
  15. void test(TestEnum input) {
  16. printf("%d", input); // no-warning
  17. printf("%d", Constant); // no-warning
  18. printf("%lld", input); // expected-warning-re{{format specifies type 'long long' but the argument has underlying type '{{(unsigned)?}} int'}}
  19. printf("%lld", Constant); // expected-warning{{format specifies type 'long long'}}
  20. }
  21. typedef enum { LongConstant = ~0UL } LongEnum;
  22. void testLong(LongEnum input) {
  23. printf("%u", input); // expected-warning{{format specifies type 'unsigned int' but the argument has underlying type}}
  24. printf("%u", LongConstant); // expected-warning{{format specifies type 'unsigned int'}}
  25. printf("%lu", input);
  26. printf("%lu", LongConstant);
  27. }