p4.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. namespace A {
  3. class A {
  4. friend void func(A);
  5. friend A operator+(A,A);
  6. };
  7. }
  8. namespace B {
  9. class B {
  10. static void func(B);
  11. };
  12. B operator+(B,B);
  13. }
  14. namespace D {
  15. class D {};
  16. }
  17. namespace C {
  18. class C {}; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'B::B' to 'const C::C &' for 1st argument}}
  19. void func(C); // expected-note {{'C::func' declared here}} \
  20. // expected-note {{passing argument to parameter here}}
  21. C operator+(C,C);
  22. D::D operator+(D::D,D::D);
  23. }
  24. namespace D {
  25. using namespace C;
  26. }
  27. namespace Test {
  28. void test() {
  29. func(A::A());
  30. // FIXME: namespace-aware typo correction causes an extra, misleading
  31. // message in this case; some form of backtracking, diagnostic message
  32. // delaying, or argument checking before emitting diagnostics is needed to
  33. // avoid accepting and printing out a typo correction that proves to be
  34. // incorrect once argument-dependent lookup resolution has occurred.
  35. func(B::B()); // expected-error {{use of undeclared identifier 'func'; did you mean 'C::func'?}} \
  36. // expected-error {{no viable conversion from 'B::B' to 'C::C'}}
  37. func(C::C());
  38. A::A() + A::A();
  39. B::B() + B::B();
  40. C::C() + C::C();
  41. D::D() + D::D(); // expected-error {{invalid operands to binary expression ('D::D' and 'D::D')}}
  42. }
  43. }
  44. // PR6716
  45. namespace test1 {
  46. template <class T> class A {
  47. template <class U> friend void foo(A &, U); // expected-note {{not viable: 1st argument ('const A<int>') would lose const qualifier}}
  48. public:
  49. A();
  50. };
  51. void test() {
  52. const A<int> a;
  53. foo(a, 10); // expected-error {{no matching function for call to 'foo'}}
  54. }
  55. }