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