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
8 friend A
operator+(A
,A
);
24 class C
{}; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'B::B' to 'const C &' for 1st argument}}
25 #if __cplusplus >= 201103L // C++11 or later
26 // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'B::B' to 'C &&' for 1st argument}}
28 void func(C
); // expected-note {{'C::func' declared here}} \
29 // expected-note {{passing argument to parameter here}}
31 D::D
operator+(D::D
,D::D
);
41 // FIXME: namespace-aware typo correction causes an extra, misleading
42 // message in this case; some form of backtracking, diagnostic message
43 // delaying, or argument checking before emitting diagnostics is needed to
44 // avoid accepting and printing out a typo correction that proves to be
45 // incorrect once argument-dependent lookup resolution has occurred.
46 func(B::B()); // expected-error {{use of undeclared identifier 'func'; did you mean 'C::func'?}} \
47 // expected-error {{no viable conversion from 'B::B' to 'C'}}
52 D::D() + D::D(); // expected-error {{invalid operands to binary expression ('D::D' and 'D::D')}}
58 template <class T
> class A
{
59 template <class U
> friend void foo(A
&, U
); // expected-note {{not viable: 1st argument ('const A<int>') would lose const qualifier}}
67 foo(a
, 10); // expected-error {{no matching function for call to 'foo'}}
72 // Check the rules described in p4:
73 // When considering an associated namespace, the lookup is the same as the lookup
74 // performed when the associated namespace is used as a qualifier (6.4.3.2) except that:
76 // - Any using-directives in the associated namespace are ignored.
77 namespace test_using_directives
{
78 namespace M
{ struct S
; }
80 void f(M::S
); // expected-note {{declared here}}
88 f(s
); // expected-error {{use of undeclared}}
93 // - Any namespace-scope friend functions or friend function templates declared in
94 // associated classes are visible within their respective namespaces even if
95 // they are not visible during an ordinary lookup
96 // (Note: For the friend declaration to be visible, the corresponding class must be
97 // included in the set of associated classes. Merely including the namespace in
98 // the set of associated namespaces is not enough.)
99 namespace test_friend1
{
103 friend void f(S
); // #1
105 struct S
{ S(); S(T
); };
111 f(s
); // expected-error {{use of undeclared}}
116 // credit: Arthur O’Dwyer
117 namespace test_friend2
{
122 friend void foo(...); // #1
126 friend void foo(...); // #2
128 template<class> struct E
{
132 template<class> struct G
{};
133 template<class> struct H
{};
134 template<class> struct I
{};
135 struct J
{ friend void foo(...) {} }; // #3
139 foo(c
); // #1 is not visible since A is not an associated class
140 // expected-error@-1 {{use of undeclared}}
142 foo(f
); // #2 is not visible since D is not an associated class
143 // expected-error@-1 {{use of undeclared}}
149 // - All names except those of (possibly overloaded) functions and
150 // function templates are ignored.
151 namespace test_other_names
{
154 struct Callable
{ void operator()(S
); };
155 static struct Callable Callable
;
160 Callable(s
); // expected-error {{use of undeclared}}