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
15 Int
typedeffed_member();
18 struct Derived
: public Base
{
23 void global_function();
25 void global_c_function();
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'}}
46 friend void A::a_member();
47 #if __cplusplus <= 199711L
48 // expected-error@-2 {{friends cannot be members of the declaring class}}
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
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)
72 friend class facet
; // should not assert
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'}}
84 int myoperation(float f
) {
91 friend B
<U
>() {} // expected-error {{must use a qualified name when declaring a constructor as a friend}}