| 1 |
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify %s -std=c++14 |
| 2 |
|
| 3 |
int FileScope; |
| 4 |
|
| 5 |
struct A { |
| 6 |
int I; |
| 7 |
void f(); |
| 8 |
A() try { |
| 9 |
} catch (...) { |
| 10 |
I = 12; // expected-warning {{cannot refer to a non-static member from the handler of a constructor function try block}} |
| 11 |
f(); // expected-warning {{cannot refer to a non-static member from the handler of a constructor function try block}} |
| 12 |
|
| 13 |
FileScope = 12; // ok |
| 14 |
A a; |
| 15 |
a.I = 12; // ok |
| 16 |
} |
| 17 |
}; |
| 18 |
|
| 19 |
struct B { |
| 20 |
int I; |
| 21 |
void f(); |
| 22 |
}; |
| 23 |
|
| 24 |
struct C : B { |
| 25 |
C() try { |
| 26 |
} catch (...) { |
| 27 |
I = 12; // expected-warning {{cannot refer to a non-static member from the handler of a constructor function try block}} |
| 28 |
f(); // expected-warning {{cannot refer to a non-static member from the handler of a constructor function try block}} |
| 29 |
} |
| 30 |
}; |
| 31 |
|
| 32 |
struct D { |
| 33 |
static int I; |
| 34 |
static void f(); |
| 35 |
|
| 36 |
D() try { |
| 37 |
} catch (...) { |
| 38 |
I = 12; // ok |
| 39 |
f(); // ok |
| 40 |
} |
| 41 |
}; |
| 42 |
int D::I; |
| 43 |
|
| 44 |
struct E { |
| 45 |
int I; |
| 46 |
void f(); |
| 47 |
static int J; |
| 48 |
static void g(); |
| 49 |
|
| 50 |
~E() try { |
| 51 |
} catch (...) { |
| 52 |
I = 12; // expected-warning {{cannot refer to a non-static member from the handler of a destructor function try block}} |
| 53 |
f(); // expected-warning {{cannot refer to a non-static member from the handler of a destructor function try block}} |
| 54 |
|
| 55 |
J = 12; // ok |
| 56 |
g(); // ok |
| 57 |
} |
| 58 |
}; |
| 59 |
int E::J; |
| 60 |
|
| 61 |
struct F { |
| 62 |
static int I; |
| 63 |
static void f(); |
| 64 |
}; |
| 65 |
int F::I; |
| 66 |
|
| 67 |
struct G : F { |
| 68 |
G() try { |
| 69 |
} catch (...) { |
| 70 |
I = 12; // ok |
| 71 |
f(); // ok |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
struct H { |
| 76 |
struct A {}; |
| 77 |
enum { |
| 78 |
E |
| 79 |
}; |
| 80 |
|
| 81 |
H() try { |
| 82 |
} catch (...) { |
| 83 |
H::A a; // ok |
| 84 |
int I = E; // ok |
| 85 |
} |
| 86 |
}; |
| 87 |
|
| 88 |
struct I { |
| 89 |
int J; |
| 90 |
|
| 91 |
I() { |
| 92 |
try { // not a function-try-block |
| 93 |
} catch (...) { |
| 94 |
J = 12; // ok |
| 95 |
} |
| 96 |
} |
| 97 |
}; |