xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjCXX/warn-objc-literal-conversion.mm (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify -Wobjc-literal-conversion %s
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc@class NSString;
4*0a6a1f1dSLionel Sambuc
5*0a6a1f1dSLionel Sambuc@interface NSNumber
6*0a6a1f1dSLionel Sambuc+ (NSNumber *)numberWithChar:(char)value;
7*0a6a1f1dSLionel Sambuc+ (NSNumber *)numberWithInt:(int)value;
8*0a6a1f1dSLionel Sambuc+ (NSNumber *)numberWithLongLong:(long long)value;
9*0a6a1f1dSLionel Sambuc+ (NSNumber *)numberWithFloat:(float)value;
10*0a6a1f1dSLionel Sambuc+ (NSNumber *)numberWithDouble:(double)value;
11*0a6a1f1dSLionel Sambuc+ (NSNumber *)numberWithBool:(bool)value;
12*0a6a1f1dSLionel Sambuc@end
13*0a6a1f1dSLionel Sambuc
14*0a6a1f1dSLionel Sambuc@interface NSArray
15*0a6a1f1dSLionel Sambuc+ (id)arrayWithObjects:(const id [])objects count:(int)cnt;
16*0a6a1f1dSLionel Sambuc@end
17*0a6a1f1dSLionel Sambuc
18*0a6a1f1dSLionel Sambuc@interface NSDictionary
19*0a6a1f1dSLionel Sambuc+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
20*0a6a1f1dSLionel Sambuc@end
21*0a6a1f1dSLionel Sambuc
22*0a6a1f1dSLionel Sambucvoid char_test() {
23*0a6a1f1dSLionel Sambuc  if (@'a') {}
24*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
25*0a6a1f1dSLionel Sambuc}
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel Sambucvoid int_test() {
28*0a6a1f1dSLionel Sambuc  if (@12) {}
29*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
30*0a6a1f1dSLionel Sambuc  if (@-12) {}
31*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
32*0a6a1f1dSLionel Sambuc  if (@12LL) {}
33*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
34*0a6a1f1dSLionel Sambuc  if (@-12LL) {}
35*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
36*0a6a1f1dSLionel Sambuc}
37*0a6a1f1dSLionel Sambuc
38*0a6a1f1dSLionel Sambucvoid float_test() {
39*0a6a1f1dSLionel Sambuc  if (@12.55) {}
40*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
41*0a6a1f1dSLionel Sambuc  if (@-12.55) {}
42*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
43*0a6a1f1dSLionel Sambuc  if (@12.55F) {}
44*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
45*0a6a1f1dSLionel Sambuc  if (@-12.55F) {}
46*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
47*0a6a1f1dSLionel Sambuc}
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel Sambucvoid bool_test() {
50*0a6a1f1dSLionel Sambuc  if (@true) {}
51*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
52*0a6a1f1dSLionel Sambuc  if (@false) {}
53*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
54*0a6a1f1dSLionel Sambuc}
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambucvoid string_test() {
57*0a6a1f1dSLionel Sambuc  if (@"asdf") {}
58*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
59*0a6a1f1dSLionel Sambuc}
60*0a6a1f1dSLionel Sambuc
61*0a6a1f1dSLionel Sambucvoid array_test() {
62*0a6a1f1dSLionel Sambuc  if (@[ @313, @331, @367, @379 ]) {}
63*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
64*0a6a1f1dSLionel Sambuc}
65*0a6a1f1dSLionel Sambuc
66*0a6a1f1dSLionel Sambucvoid dictionary_test() {
67*0a6a1f1dSLionel Sambuc  if (@{ @0: @0, @1: @1, @2: @1, @3: @3 }) {}
68*0a6a1f1dSLionel Sambuc  // expected-warning@-1{{implicit boolean conversion of Objective-C object literal always evaluates to true}}
69*0a6a1f1dSLionel Sambuc}
70*0a6a1f1dSLionel Sambuc
71*0a6a1f1dSLionel Sambucvoid objc_bool_test () {
72*0a6a1f1dSLionel Sambuc  if (__objc_yes) {}
73*0a6a1f1dSLionel Sambuc  if (__objc_no) {}
74*0a6a1f1dSLionel Sambuc}
75