53 lines · plain
1// RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat %s2// RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat-pedantic -DPEDANTIC %s3// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify %s4// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify -Wformat-pedantic -DPEDANTIC %s5 6#if !defined(PEDANTIC)7// expected-no-diagnostics8#endif9 10#if __LP64__11typedef unsigned long NSUInteger;12typedef long NSInteger;13typedef long ptrdiff_t;14#else15typedef unsigned int NSUInteger;16typedef int NSInteger;17#if __is_target_os(watchos)18 // Watch ABI uses long for ptrdiff_t.19 typedef long ptrdiff_t;20#else21 typedef int ptrdiff_t;22#endif23#endif24 25@class NSString;26 27extern void NSLog(NSString *format, ...);28 29void testSizeSpecifier(void) {30 NSInteger i = 0;31 NSUInteger j = 0;32 NSLog(@"max NSInteger = %zi", i);33 NSLog(@"max NSUinteger = %zu", j);34 35#if defined(PEDANTIC)36 // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}37 // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}38#endif39}40 41void testPtrdiffSpecifier(ptrdiff_t x) {42 NSInteger i = 0;43 NSUInteger j = 0;44 45 NSLog(@"ptrdiff_t NSUinteger: %tu", j);46 NSLog(@"ptrdiff_t NSInteger: %td", i);47 NSLog(@"ptrdiff_t %tu, %td", x, x);48#if __is_target_os(watchos) && defined(PEDANTIC)49 // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}50 // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}51#endif52}53