diff options
Diffstat (limited to 'clang/test/Sema/format-strings-enum.c')
-rw-r--r-- | clang/test/Sema/format-strings-enum.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/test/Sema/format-strings-enum.c b/clang/test/Sema/format-strings-enum.c index e79f8598ab4..ba077a887e0 100644 --- a/clang/test/Sema/format-strings-enum.c +++ b/clang/test/Sema/format-strings-enum.c @@ -11,6 +11,7 @@ #endif EXTERN_C int printf(const char *,...); +EXTERN_C int scanf(const char *, ...); typedef enum { Constant = 0 } TestEnum; // Note that in C, the type of 'Constant' is 'int'. In C++ it is 'TestEnum'. @@ -34,3 +35,18 @@ void testLong(LongEnum input) { printf("%lu", input); printf("%lu", LongConstant); } + +#ifndef __cplusplus +// GNU C allows forward declaring enums. +extern enum forward_declared *fwd; + +void forward_enum() { + printf("%u", fwd); // expected-warning{{format specifies type 'unsigned int' but the argument has type 'enum forward_declared *}} + printf("%p", fwd); + + scanf("%c", fwd); // expected-warning{{format specifies type 'char *' but the argument has type 'enum forward_declared *}} + scanf("%u", fwd); + scanf("%lu", fwd); // expected-warning{{format specifies type 'unsigned long *' but the argument has type 'enum forward_declared *}} + scanf("%p", fwd); // expected-warning{{format specifies type 'void **' but the argument has type 'enum forward_declared *}} +} +#endif |