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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62117 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index 16d4943..19c29db 100644
--- a/test/Sema/format-strings.c
+++ b/test/Sema/format-strings.c
@@ -31,6 +31,12 @@
__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;