From 6dfeb558979b44bc32a74a9849b39bdbdac96eb7 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 12 Jan 2009 23:09:09 +0000 Subject: Patch by Roman Divacky: Extend string-literal checking for printf() format string to handle conditional ternary operators where both sides are literals. This fixes PR 3319: http://llvm.org/bugs/show_bug.cgi?id=3319 llvm-svn: 62117 --- clang/test/Sema/format-strings.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'clang/test/Sema') diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 16d4943cda5..19c29db343d 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -31,6 +31,12 @@ void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { __builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a string literal}} } +void check_conditional_literal(const char* s, int i) { + printf(i == 1 ? "yes" : "no"); // no-warning + printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning + printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning +} + void check_writeback_specifier() { int x; -- cgit v1.2.3