friend.cpp 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. template<typename T> struct A {
  3. struct B { };
  4. friend struct B;
  5. };
  6. void f() {
  7. A<int>::B b;
  8. }
  9. struct C0 {
  10. friend struct A<int>;
  11. };
  12. namespace PR6770 {
  13. namespace N {
  14. int f1(int);
  15. }
  16. using namespace N;
  17. namespace M {
  18. float f1(float);
  19. }
  20. using M::f1;
  21. template<typename T> void f1(T, T);
  22. template <class T>
  23. void f() {
  24. friend class f; // expected-error{{'friend' used outside of class}}
  25. friend class f1; // expected-error{{'friend' used outside of class}}
  26. }
  27. }
  28. namespace friend_redecl_inline {
  29. // We had a bug where instantiating the foo friend declaration would check the
  30. // defined-ness of the most recent decl while checking if the canonical decl was
  31. // inlined.
  32. void foo();
  33. void bar();
  34. template <typename T>
  35. class C {
  36. friend void foo();
  37. friend inline void bar();
  38. };
  39. inline void foo() {}
  40. inline void bar() {}
  41. C<int> c;
  42. }