| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
namespace T1 { |
| 3 |
|
| 4 |
class A { }; |
| 5 |
class B : private A { }; // expected-note {{declared private here}} |
| 6 |
|
| 7 |
void f(B* b) { |
| 8 |
A *a = b; // expected-error{{cannot cast 'B' to its private base class 'A'}} |
| 9 |
} |
| 10 |
|
| 11 |
} |
| 12 |
|
| 13 |
namespace T2 { |
| 14 |
|
| 15 |
class A { }; |
| 16 |
class B : A { }; // expected-note {{implicitly declared private here}} |
| 17 |
|
| 18 |
void f(B* b) { |
| 19 |
A *a = b; // expected-error {{cannot cast 'B' to its private base class 'A'}} |
| 20 |
} |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
namespace T3 { |
| 25 |
|
| 26 |
class A { }; |
| 27 |
class B : public A { }; |
| 28 |
|
| 29 |
void f(B* b) { |
| 30 |
A *a = b; |
| 31 |
} |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
namespace T4 { |
| 36 |
|
| 37 |
class A {}; |
| 38 |
|
| 39 |
class B : private virtual A {}; |
| 40 |
class C : public virtual A {}; |
| 41 |
|
| 42 |
class D : public B, public C {}; |
| 43 |
|
| 44 |
void f(D *d) { |
| 45 |
// This takes the D->C->B->A path. |
| 46 |
A *a = d; |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
namespace T5 { |
| 52 |
class A {}; |
| 53 |
|
| 54 |
class B : private A { |
| 55 |
void f(B *b) { |
| 56 |
A *a = b; |
| 57 |
} |
| 58 |
}; |
| 59 |
} |
| 60 |
|
| 61 |
namespace T6 { |
| 62 |
class C; |
| 63 |
|
| 64 |
class A {}; // expected-note{{member is declared here}} |
| 65 |
|
| 66 |
class B : private A { // expected-note {{declared private here}} expected-note {{constrained by private inheritance here}} |
| 67 |
void f(C* c); |
| 68 |
}; |
| 69 |
|
| 70 |
class C : public B { |
| 71 |
void f(C *c) { |
| 72 |
A* a = c; // expected-error {{cannot cast 'C' to its private base class 'A'}} \ |
| 73 |
// expected-error {{'A' is a private member of 'T6::A'}} |
| 74 |
} |
| 75 |
}; |
| 76 |
|
| 77 |
void B::f(C *c) { |
| 78 |
A *a = c; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
namespace T7 { |
| 83 |
class A {}; |
| 84 |
class B : public A {}; |
| 85 |
class C : private B { |
| 86 |
void f(C *c) { |
| 87 |
A* a = c; // okay |
| 88 |
} |
| 89 |
}; |
| 90 |
} |
| 91 |
|
| 92 |
namespace T8 { |
| 93 |
template <int> |
| 94 |
struct flag { |
| 95 |
static constexpr bool value = true; |
| 96 |
}; |
| 97 |
|
| 98 |
template <class T> |
| 99 |
struct trait : flag<sizeof(T)> {}; // expected-note 2{{here}} |
| 100 |
|
| 101 |
template <class T, bool Inferred = trait<T>::value> // expected-note {{here}} |
| 102 |
struct a {}; |
| 103 |
|
| 104 |
template <class T> |
| 105 |
class b { |
| 106 |
a<T> x; // expected-note {{here}} |
| 107 |
using U = a<T>; |
| 108 |
}; |
| 109 |
|
| 110 |
template <int> |
| 111 |
struct Impossible { |
| 112 |
static_assert(false, ""); // expected-error {{static assertion failed}} |
| 113 |
}; |
| 114 |
|
| 115 |
// verify "no member named 'value'" bogus diagnostic is not emitted. |
| 116 |
trait<b<Impossible<0>>>::value; // expected-note {{here}} |
| 117 |
} // namespace T8 |