xref: /llvm-project/clang/test/SemaObjCXX/delay-parsing-func-tryblock.mm (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -x objective-c++ -fcxx-exceptions -fsyntax-only -Werror -verify -Wno-objc-root-class %s
2
3@interface MyClass
4- (void)someMethod;
5@end
6
7struct BadReturn {
8  BadReturn(MyClass * myObject);
9  int bar(MyClass * myObject);
10  void MemFunc(MyClass * myObject);
11  int i;
12  MyClass *CObj;
13};
14
15@implementation MyClass
16- (void)someMethod {
17    [self privateMethod];  // clang already does not warn here
18}
19
20int BadReturn::bar(MyClass * myObject) {
21    [myObject privateMethod];
22    return 0;
23}
24
25BadReturn::BadReturn(MyClass * myObject) try : CObj(myObject) {
26} catch(...) {
27  try {
28    [myObject privateMethod];
29    [myObject privateMethod1];
30    getMe = bar(myObject); // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
31    [CObj privateMethod1]; // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
32  } catch(int ei) {
33    i = ei; // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
34  } catch(...) {
35    {
36      i = 0; // expected-error {{cannot refer to a non-static member from the handler of a constructor function try block}}
37    }
38  }
39}
40
41void BadReturn::MemFunc(MyClass * myObject) try {
42} catch(...) {
43  try {
44    [myObject privateMethod];
45    [myObject privateMethod1];
46    getMe = bar(myObject);
47    [CObj privateMethod1];
48  } catch(int ei) {
49    i = ei;
50  } catch(...) {
51    {
52      i = 0;
53    }
54  }
55}
56
57- (void)privateMethod { }
58
59- (void)privateMethod1 {
60  getMe = getMe+1;
61}
62
63static int getMe;
64
65@end
66