[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / cxx2c-variadic-friends.cpp
bloba4d7c8078338d2a6e22bef2468743f471003197e
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c %s
3 struct A;
4 struct B;
5 struct C;
7 struct S {};
8 template <typename> struct TS {};
10 template <typename ...Pack>
11 class X {
12 friend Pack...;
13 static void f() { } // expected-note {{declared private here}}
16 class Y {
17 friend A, B, C;
18 static void g() { } // expected-note {{declared private here}}
21 struct A {
22 A() {
23 X<A>::f();
24 Y::g();
28 struct B {
29 B() {
30 X<B, C>::f();
31 Y::g();
35 struct C {
36 C() {
37 X<A, B, C>::f();
38 Y::g();
42 struct D {
43 D() {
44 X<A, B, C>::f(); // expected-error {{'f' is a private member of 'X<A, B, C>'}}
45 Y::g(); // expected-error {{'g' is a private member of 'Y'}}
49 void f1() {
50 A a;
51 B b;
52 C c;
53 D d;
56 template <typename ...Pack>
57 struct Z {
58 template <template <typename> class Template>
59 struct Inner {
60 friend Template<Pack>...;
64 void f2() {
65 Z<int, long, char> z;
66 Z<int, long, char>::Inner<TS> inner;
69 namespace p2893r3_examples {
70 template<class... Ts>
71 class Passkey {
72 friend Ts...;
73 Passkey() {} // expected-note {{declared private here}}
76 class Foo;
77 class Bar;
78 class Baz;
80 class C {
81 public:
82 void f(Passkey<Foo, Bar, Baz>);
85 class Foo {
86 Foo() { C c; c.f({}); }
89 class Bar {
90 Bar() { C c; c.f({}); }
93 class Baz {
94 Baz() { C c; c.f({}); }
97 class Quux {
98 Quux() { C c; c.f({}); } // expected-error {{calling a private constructor of class 'p2893r3_examples::Passkey<p2893r3_examples::Foo, p2893r3_examples::Bar, p2893r3_examples::Baz>'}}
101 template<class Derived, class MsgT>
102 struct Receiver {
103 void receive(MsgT) {
104 static_cast<Derived*>(this)->private_ += 1;
108 template<class... MsgTs>
109 struct Dispatcher : Receiver<Dispatcher<MsgTs...>, MsgTs>... {
110 using Receiver<Dispatcher, MsgTs>::receive...;
111 friend Receiver<Dispatcher, MsgTs>...;
113 private:
114 int private_;
117 void f() {
118 Dispatcher<int, float> d;
119 d.receive(0);
120 d.receive(0.0f);
122 } // namespace p2893r3_examples
124 namespace p2893r3_note {
125 template <class... Ts> class R {
126 friend Ts...;
129 template <class... Ts, class... Us>
130 class R<R<Ts...>, R<Us...>> {
131 friend Ts::Nested..., Us...;
134 struct E { struct Nested; };
135 R<R<E>, R<C, int>> rr;
136 } // namespace p2893r3_note
138 namespace template_template {
139 template <typename U, template <typename> typename... Friend>
140 class S {
141 friend class Friend<U>...;
142 static constexpr int a = 42;
145 template <typename U>
146 struct T {
147 static_assert(S<U, T>::a == 42);
148 static_assert(S<U, T>::a == 43); // expected-error {{static assertion failed due to requirement 'S<int, template_template::T>::a == 43'}} \
149 // expected-note {{expression evaluates to '42 == 43'}}
152 void f() {
153 T<int> t; // expected-note {{in instantiation of}}