diff options
author | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-21 20:00:53 +0000 |
---|---|---|
committer | Jean-Daniel Dupas <devlists@shadowlab.org> | 2012-02-21 20:00:53 +0000 |
commit | f57c413e444b441fa75ae8911d183c19b53bdd56 (patch) | |
tree | 8242e39f4ac230f2c3348e89f45d48354439df33 /test/SemaObjC/format-strings-objc.m | |
parent | f4b7de1cef3007cc0479775638198287384d9af1 (diff) |
When calling a non variadic format function(vprintf, vscanf, NSLogv, …), warn if the format string argument is a parameter that is not itself declared as a format string with compatible format.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151080 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaObjC/format-strings-objc.m')
-rw-r--r-- | test/SemaObjC/format-strings-objc.m | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index 675729ca1e..a2a926c7d0 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -9,11 +9,13 @@ // portable to non-Mac platforms. //===----------------------------------------------------------------------===// +#include <stdarg.h> + typedef signed char BOOL; typedef unsigned int NSUInteger; @class NSString, Protocol; -extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); -extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); +extern void NSLog(NSString *format, ...); +extern void NSLogv(NSString *format, va_list args); typedef struct _NSZone NSZone; @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; @protocol NSObject - (BOOL)isEqual:(id)object; @end @@ -151,3 +153,26 @@ void test_percent_C() { void test_toll_free_bridging(CFStringRef x) { NSLog(@"%@", x); // no-warning } + +@interface Bar ++ (void)log:(NSString *)fmt, ...; ++ (void)log2:(NSString *)fmt, ... __attribute__((format(NSString, 1, 2))); +@end + +@implementation Bar + ++ (void)log:(NSString *)fmt, ... { + va_list ap; + va_start(ap,fmt); + NSLogv(fmt, ap); // expected-warning{{format string is not a string literal}} + va_end(ap); +} + ++ (void)log2:(NSString *)fmt, ... { + va_list ap; + va_start(ap,fmt); + NSLogv(fmt, ap); // no-warning + va_end(ap); +} + +@end |