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