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 
7 #ifdef __cplusplus
8 # define EXTERN_C extern "C"
9 #else
10 # define EXTERN_C extern
11 #endif
12 
13 EXTERN_C int printf(const char *,...);
14 EXTERN_C int scanf(const char *, ...);
15 
16 typedef enum { Constant = 0 } TestEnum;
17 // Note that in C, the type of 'Constant' is 'int'. In C++ it is 'TestEnum'.
18 // This is why we don't check for that in the expected output.
19 
test(TestEnum input)20 void test(TestEnum input) {
21     printf("%d", input); // no-warning
22     printf("%d", Constant); // no-warning
23 
24     printf("%lld", input); // expected-warning-re{{format specifies type 'long long' but the argument has underlying type '{{(unsigned)?}} int'}}
25     printf("%lld", Constant); // expected-warning{{format specifies type 'long long'}}
26 }
27 
28 
29 typedef enum { LongConstant = ~0UL } LongEnum;
30 
testLong(LongEnum input)31 void testLong(LongEnum input) {
32   printf("%u", input); // expected-warning{{format specifies type 'unsigned int' but the argument has underlying type}}
33   printf("%u", LongConstant); // expected-warning{{format specifies type 'unsigned int'}}
34 
35   printf("%lu", input);
36   printf("%lu", LongConstant);
37 }
38 
39 #ifndef __cplusplus
40 // GNU C allows forward declaring enums.
41 extern enum forward_declared *fwd;
42 
forward_enum()43 void forward_enum() {
44   printf("%u", fwd); // expected-warning{{format specifies type 'unsigned int' but the argument has type 'enum forward_declared *}}
45   printf("%p", fwd);
46 
47   scanf("%c", fwd); // expected-warning{{format specifies type 'char *' but the argument has type 'enum forward_declared *}}
48   scanf("%u", fwd);
49   scanf("%lu", fwd); // expected-warning{{format specifies type 'unsigned long *' but the argument has type 'enum forward_declared *}}
50   scanf("%p", fwd); // expected-warning{{format specifies type 'void **' but the argument has type 'enum forward_declared *}}
51 }
52 #endif
53