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