Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / class / class.friend / p1.cpp
blob08498c07330e536679021bf78e25f09284c36c4e
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 struct Outer {
6 struct Inner {
7 int intfield;
8 };
9 };
11 struct Base {
12 void base_member();
14 typedef int Int;
15 Int typedeffed_member();
18 struct Derived : public Base {
21 int myglobal;
23 void global_function();
24 extern "C" {
25 void global_c_function();
28 class A {
29 class AInner {
32 friend class PreDeclared;
33 friend class Outer::Inner;
34 friend int Outer::Inner::intfield; // expected-error {{friends can only be classes or functions}}
35 friend int Outer::Inner::missing_field; //expected-error {{friends can only be classes or functions}}
36 friend int myoperation(float); // okay
37 friend int myglobal; // expected-error {{friends can only be classes or functions}}
39 friend void global_function();
40 friend void global_c_function();
42 friend class UndeclaredSoFar;
43 UndeclaredSoFar x; // expected-error {{unknown type name 'UndeclaredSoFar'}}
45 void a_member();
46 friend void A::a_member();
47 #if __cplusplus <= 199711L
48 // expected-error@-2 {{friends cannot be members of the declaring class}}
49 #endif
50 friend void a_member(); // okay (because we ignore class scopes when looking up friends)
51 friend class A::AInner; // this is okay as an extension
52 friend class AInner; // okay, refers to ::AInner
54 friend void Derived::missing_member(); // expected-error {{friend declaration of 'missing_member' does not match any declaration in 'Derived'}}
56 friend void Derived::base_member(); // expected-error {{friend declaration of 'base_member' does not match any declaration in 'Derived'}}
58 friend int Base::typedeffed_member(); // okay: should look through typedef
60 // These test that the friend is properly not being treated as a
61 // member function.
62 friend A operator|(const A& l, const A& r); // okay
63 friend A operator|(const A& r); // expected-error {{overloaded 'operator|' must be a binary operator (has 1 parameter)}}
65 friend operator bool() const; // expected-error {{must use a qualified name when declaring a conversion operator as a friend}} \
66 // expected-error{{non-member function cannot have 'const' qualifier}}
68 typedef void ftypedef();
69 friend ftypedef typedeffed_function; // okay (because it's not declared as a member)
71 class facet;
72 friend class facet; // should not assert
73 class facet {};
75 friend int Unknown::thing(); // expected-error {{use of undeclared identifier}}
76 friend int friendfunc(), Unknown::thing(); // expected-error {{use of undeclared identifier}}
77 friend int friendfunc(), Unknown::thing() : 4; // expected-error {{use of undeclared identifier}}
80 A::UndeclaredSoFar y; // expected-error {{no type named 'UndeclaredSoFar' in 'A'}}
82 class PreDeclared;
84 int myoperation(float f) {
85 return (int) f;
88 template <typename T>
89 class B {
90 template <typename U>
91 friend B<U>() {} // expected-error {{must use a qualified name when declaring a constructor as a friend}}