[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / cxx-friend.cpp
bloba4492ba1a7ab940dcb03b34971e6ef30edc84649
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 class C {
6 friend class D;
7 };
9 class A {
10 public:
11 void f();
14 friend int x; // expected-error {{'friend' used outside of class}}
16 friend class D {}; // expected-error {{'friend' used outside of class}}
18 union U {
19 int u1;
22 class B {
23 // 'A' here should refer to the declaration above.
24 friend class A;
26 friend C;
27 #if __cplusplus <= 199711L
28 // expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'class' to befriend 'C'}}
29 #endif
31 friend U;
32 #if __cplusplus <= 199711L
33 // expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'union' to befriend 'U'}}
34 #endif
36 friend int;
37 #if __cplusplus <= 199711L
38 // expected-warning@-2 {{non-class friend type 'int' is a C++11 extension}}
39 #endif
41 friend void myfunc();
43 void f(A *a) { a->f(); }
46 inline void bar() {} // expected-note {{previous definition is here}}
47 class E {
48 friend void bar() {} // expected-error {{redefinition of 'bar'}}
54 template <typename t1, typename t2> class some_template;
55 friend // expected-error {{'friend' used outside of class}}
56 some_template<foo, bar>& // expected-error {{use of undeclared identifier 'foo'}}
57 ; // expected-error {{expected unqualified-id}}