]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/dynamic_type_check.m
Vendor import of clang trunk r300422:
[FreeBSD/FreeBSD.git] / test / Analysis / dynamic_type_check.m
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core.DynamicTypeChecker -verify %s
2
3
4 #define nil 0
5 typedef unsigned long NSUInteger;
6 typedef int BOOL;
7
8 @protocol NSObject
9 + (id)alloc;
10 - (id)init;
11 @end
12
13 @protocol NSCopying
14 @end
15
16 __attribute__((objc_root_class))
17 @interface NSObject <NSObject>
18 @end
19
20 @interface NSString : NSObject <NSCopying>
21 @end
22
23 @interface NSMutableString : NSString
24 @end
25
26 @interface NSNumber : NSObject <NSCopying>
27 @end
28
29 @class MyType;
30
31 void testTypeCheck(NSString* str) {
32   id obj = str;
33   NSNumber *num = obj; // expected-warning {{}}
34   (void)num;
35 }
36
37 void testForwardDeclarations(NSString* str) {
38   id obj = str;
39   // Do not warn, since no information is available wether MyType is a sub or
40   // super class of any other type.
41   MyType *num = obj; // no warning
42   (void)num;
43 }