blob: f6b849b955836c180d35812043d36566d008d48f [file] [log] [blame]
Fariborz Jahanian8cecfe92012-08-10 18:10:56 +00001// RUN: %clang_cc1 -x objective-c++ -fcxx-exceptions -fsyntax-only -Werror -verify -Wno-objc-root-class %s
2// rdar://10387088
3
4@interface MyClass
5- (void)someMethod;
6@end
7
8struct BadReturn {
9 BadReturn(MyClass * myObject);
10 int bar(MyClass * myObject);
Fariborz Jahanian053227f2012-08-10 20:34:17 +000011 void MemFunc(MyClass * myObject);
Fariborz Jahanian8cecfe92012-08-10 18:10:56 +000012 int i;
Fariborz Jahanian053227f2012-08-10 20:34:17 +000013 MyClass *CObj;
Fariborz Jahanian8cecfe92012-08-10 18:10:56 +000014};
15
16@implementation MyClass
17- (void)someMethod {
18 [self privateMethod]; // clang already does not warn here
19}
20
21int BadReturn::bar(MyClass * myObject) {
22 [myObject privateMethod];
23 return 0;
24}
25
Fariborz Jahanian053227f2012-08-10 20:34:17 +000026BadReturn::BadReturn(MyClass * myObject) try : CObj(myObject) {
Fariborz Jahanian8cecfe92012-08-10 18:10:56 +000027} catch(...) {
28 try {
29 [myObject privateMethod];
30 [myObject privateMethod1];
Aaron Ballman6924dcd2015-09-01 14:49:24 +000031 getMe = bar(myObject); // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
32 [CObj privateMethod1]; // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
Fariborz Jahanian053227f2012-08-10 20:34:17 +000033 } catch(int ei) {
Aaron Ballman6924dcd2015-09-01 14:49:24 +000034 i = ei; // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
Fariborz Jahanian053227f2012-08-10 20:34:17 +000035 } catch(...) {
36 {
Aaron Ballman6924dcd2015-09-01 14:49:24 +000037 i = 0; // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
Fariborz Jahanian053227f2012-08-10 20:34:17 +000038 }
39 }
40}
41
42void BadReturn::MemFunc(MyClass * myObject) try {
43} catch(...) {
44 try {
45 [myObject privateMethod];
46 [myObject privateMethod1];
47 getMe = bar(myObject);
48 [CObj privateMethod1];
Fariborz Jahanian8cecfe92012-08-10 18:10:56 +000049 } catch(int ei) {
50 i = ei;
51 } catch(...) {
52 {
53 i = 0;
54 }
55 }
56}
57
58- (void)privateMethod { }
59
60- (void)privateMethod1 {
61 getMe = getMe+1;
62}
63
64static int getMe;
65
66@end