[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaTemplate / instantiate-using-decl.cpp
blob0bbb3ca9c88c8b5e1898a768ef57913edf6fb1df
1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s
4 namespace test0 {
5 namespace N { }
7 template<typename T>
8 struct A {
9 void f();
12 template<typename T>
13 struct B : A<T> {
14 using A<T>::f;
16 void g() {
17 using namespace N;
18 f();
22 template struct B<int>;
25 namespace test1 {
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}}
39 using Base2::Visit;
42 class Knot : public JoinVisitor<Knot> {
45 void test() {
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}}
52 // PR5847
53 namespace test2 {
54 namespace ns {
55 void foo();
58 template <class T> void bar(T* ptr) {
59 using ns::foo;
60 foo();
63 template void bar(char *);
66 namespace test3 {
67 template <typename T> struct t {
68 struct s1 {
69 T f1() const;
71 struct s2 : s1 {
72 using s1::f1;
73 T f1() const;
77 void f2()
79 t<int>::s2 a;
80 t<int>::s2 const & b = a;
81 b.f1();
85 namespace PR16936 {
86 // Make sure both using decls are properly considered for
87 // overload resolution.
88 template<class> struct A {
89 void access(int);
91 template<class> struct B {
92 void access();
94 template<class CELL> struct X : public A<CELL>, public B<CELL> {
95 using A<CELL>::access;
96 using B<CELL>::access;
98 void f() {
99 access(0);
103 void f() {
104 X<int> x;
105 x.f();
109 namespace pr21923 {
110 template <typename> struct Base {
111 int field;
112 void method();
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}}
119 (void)field;
120 // expected-error@+1 {{invalid use of member 'field' in static member function}}
121 (void)&field;
122 // expected-error@+1 {{call to non-static member function without an object argument}}
123 (void)method;
124 // expected-error@+1 {{call to non-static member function without an object argument}}
125 (void)&method;
126 // expected-error@+1 {{call to non-static member function without an object argument}}
127 method();
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;
135 #else
136 // expected-error@+1 {{invalid use of non-static data member 'field'}}
137 enum { TheSize = sizeof(field) };
138 #endif
141 #if __cplusplus < 201103L
142 // C++98 has an extra note for TheSize.
143 // expected-note@+2 {{requested here}}
144 #endif
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}}
154 #endif
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}}
169 } // pr21923