53 lines · c
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -verify %s2// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x c++ -verify %s3// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x c++ -std=c++11 -verify %s4// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c -verify %s5// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c++ -std=c++11 -verify %s6 7#ifdef __cplusplus8# define EXTERN_C extern "C"9#else10# define EXTERN_C extern11#endif12 13EXTERN_C int printf(const char *,...);14EXTERN_C int scanf(const char *, ...);15 16typedef 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 20void test(TestEnum input) {21 printf("%d", input); // no-warning22 printf("%d", Constant); // no-warning23 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 29typedef enum { LongConstant = ~0UL } LongEnum;30 31void 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 __cplusplus40// GNU C allows forward declaring enums.41extern enum forward_declared *fwd;42 43void forward_enum(void) {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#endif53