xref: /aosp_15_r20/external/clang/test/FixIt/format.mm (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
2*67e74705SXin Li// RUN: %clang_cc1 -fdiagnostics-parseable-fixits -fblocks %s 2>&1 | FileCheck %s
3*67e74705SXin Li
4*67e74705SXin Liextern "C" void NSLog(id, ...);
5*67e74705SXin Li
6*67e74705SXin Livoid test_percent_C() {
7*67e74705SXin Li  const unsigned short data = 'a';
8*67e74705SXin Li  NSLog(@"%C", data);  // no-warning
9*67e74705SXin Li
10*67e74705SXin Li  const wchar_t wchar_data = L'a';
11*67e74705SXin Li  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
12*67e74705SXin Li  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"(unsigned short)"
13*67e74705SXin Li
14*67e74705SXin Li  NSLog(@"%C", 0x260300);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
15*67e74705SXin Li  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
16*67e74705SXin Li  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unsigned short)"
17*67e74705SXin Li
18*67e74705SXin Li  typedef unsigned short unichar;
19*67e74705SXin Li
20*67e74705SXin Li  NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
21*67e74705SXin Li  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"(unichar)"
22*67e74705SXin Li
23*67e74705SXin Li  NSLog(@"%C", 0x260300);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'int'}}
24*67e74705SXin Li  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
25*67e74705SXin Li  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
26*67e74705SXin Li
27*67e74705SXin Li  NSLog(@"%C", 0.0); // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'double'}}
28*67e74705SXin Li  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
29*67e74705SXin Li  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
30*67e74705SXin Li}
31