format_idx, firstDataArg, Type))
return; // Literal format string found, check done!
+ // Do not emit diag when the string param is a macro expansion and the
+ // format is either NSString or CFString. This is a hack to prevent
+ // diag when using the NSLocalizedString and CFCopyLocalizedString macros
+ // which are usually used in place of NS and CF string literals.
+ if (Type == FST_NSString && Args[format_idx]->getLocStart().isMacroID())
+ return;
+
// If there are no arguments specified, warn with -Wformat-security, otherwise
// warn only with -Wformat-nonliteral.
if (NumArgs == format_idx+1)
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wformat-nonliteral -fsyntax-only -verify %s
//===----------------------------------------------------------------------===//
// The following code is reduced using delta-debugging from
NSString * ns3 = ns1;
NSLog(ns3); // expected-warning {{format string is not a string literal}}}
}
+
+// Do not emit warnings when using NSLocalizedString
+extern NSString *GetLocalizedString(NSString *str);
+#define NSLocalizedString(key) GetLocalizedString(key)
+
+void check_NSLocalizedString() {
+ [Foo fooWithFormat:NSLocalizedString(@"format"), @"arg"]; // no-warning
+}