1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s
22 template struct B
<int>;
26 template <class Derived
> struct Visitor1
{
27 void Visit(struct Object1
*);
29 template <class Derived
> struct Visitor2
{
30 void Visit(struct Object2
*); // expected-note {{candidate function}}
33 template <class Derived
> struct JoinVisitor
34 : Visitor1
<Derived
>, Visitor2
<Derived
> {
35 typedef Visitor1
<Derived
> Base1
;
36 typedef Visitor2
<Derived
> Base2
;
38 void Visit(struct Object1
*); // expected-note {{candidate function}}
42 class Knot
: public JoinVisitor
<Knot
> {
46 Knot().Visit((struct Object1
*) 0);
47 Knot().Visit((struct Object2
*) 0);
48 Knot().Visit((struct Object3
*) 0); // expected-error {{no matching member function for call}}
58 template <class T
> void bar(T
* ptr
) {
63 template void bar(char *);
67 template <typename T
> struct t
{
80 t
<int>::s2
const & b
= a
;
86 // Make sure both using decls are properly considered for
87 // overload resolution.
88 template<class> struct A
{
91 template<class> struct B
{
94 template<class CELL
> struct X
: public A
<CELL
>, public B
<CELL
> {
95 using A
<CELL
>::access
;
96 using B
<CELL
>::access
;
110 template <typename
> struct Base
{
114 template <typename Scalar
> struct Derived
: Base
<Scalar
> {
115 using Base
<Scalar
>::field
;
116 using Base
<Scalar
>::method
;
117 static void m_fn1() {
118 // expected-error@+1 {{invalid use of member 'field' in static member function}}
120 // expected-error@+1 {{invalid use of member 'field' in static member function}}
122 // expected-error@+1 {{call to non-static member function without an object argument}}
124 // expected-error@+1 {{must explicitly qualify name of member function when taking its address}}
126 // expected-error@+1 {{call to non-static member function without an object argument}}
128 (void)&Base
<Scalar
>::field
;
129 (void)&Base
<Scalar
>::method
;
131 #if __cplusplus >= 201103L
132 // These usages are OK in C++11 due to the unevaluated context.
133 enum { TheSize
= sizeof(field
) };
134 typedef decltype(field
) U
;
136 // expected-error@+1 {{invalid use of non-static data member 'field'}}
137 enum { TheSize
= sizeof(field
) };
141 #if __cplusplus < 201103L
142 // C++98 has an extra note for TheSize.
143 // expected-note@+2 {{requested here}}
145 template class Derived
<int>; // expected-note {{requested here}}
147 // This is interesting because we form an UnresolvedLookupExpr in the static
148 // function template and an UnresolvedMemberExpr in the instance function
149 // template. As a result, we get slightly different behavior.
150 struct UnresolvedTemplateNames
{
151 template <typename
> void maybe_static();
152 #if __cplusplus < 201103L
153 // expected-warning@+2 {{default template arguments for a function template are a C++11 extension}}
155 template <typename T
, typename
T::type
= 0> static void maybe_static();
157 template <typename T
>
158 void instance_method() { (void)maybe_static
<T
>(); }
159 template <typename T
>
160 static void static_method() {
161 // expected-error@+1 {{call to non-static member function without an object argument}}
162 (void)maybe_static
<T
>();
165 void force_instantiation(UnresolvedTemplateNames x
) {
166 x
.instance_method
<int>();
167 UnresolvedTemplateNames::static_method
<int>(); // expected-note {{requested here}}