cxx-friend.cpp 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. class C {
  3. friend class D;
  4. };
  5. class A {
  6. public:
  7. void f();
  8. };
  9. friend int x; // expected-error {{'friend' used outside of class}}
  10. friend class D {}; // expected-error {{'friend' used outside of class}}
  11. union U {
  12. int u1;
  13. };
  14. class B {
  15. // 'A' here should refer to the declaration above.
  16. friend class A;
  17. friend C; // expected-warning {{specify 'class' to befriend}}
  18. friend U; // expected-warning {{specify 'union' to befriend}}
  19. friend int; // expected-warning {{non-class friend type 'int'}}
  20. friend void myfunc();
  21. void f(A *a) { a->f(); }
  22. };
  23. inline void bar() {} // expected-note {{previous definition is here}}
  24. class E {
  25. friend void bar() {} // expected-error {{redefinition of 'bar'}}
  26. };
  27. template <typename t1, typename t2> class some_template;
  28. friend // expected-error {{'friend' used outside of class}}
  29. some_template<foo, bar>& // expected-error {{use of undeclared identifier 'foo'}}
  30. ; // expected-error {{expected unqualified-id}}