2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2016-04-14 04:00:45 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
2009-03-26 05:17:03 +08:00
|
|
|
|
2011-03-07 04:12:45 +08:00
|
|
|
namespace PR8965 {
|
|
|
|
template<typename T>
|
|
|
|
struct X {
|
|
|
|
typedef int type;
|
|
|
|
|
|
|
|
T field; // expected-note{{in instantiation of member class}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct Y {
|
|
|
|
struct Inner;
|
|
|
|
|
|
|
|
typedef typename X<Inner>::type // expected-note{{in instantiation of template class}}
|
|
|
|
type; // expected-note{{not-yet-instantiated member is declared here}}
|
|
|
|
|
|
|
|
struct Inner {
|
|
|
|
typedef type field; // expected-error{{no member 'type' in 'PR8965::Y<int>'; it has not yet been instantiated}}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Y<int> y; // expected-note{{in instantiation of template class}}
|
|
|
|
}
|
|
|
|
|
2009-03-26 05:17:03 +08:00
|
|
|
template<typename T>
|
|
|
|
class X {
|
|
|
|
public:
|
|
|
|
struct C { T &foo(); };
|
|
|
|
|
|
|
|
struct D {
|
2009-03-26 05:23:52 +08:00
|
|
|
struct E { T &bar(); }; // expected-error{{cannot form a reference to 'void'}}
|
2009-03-26 05:17:03 +08:00
|
|
|
struct F; // expected-note{{member is declared here}}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
X<int>::C *c1;
|
|
|
|
X<float>::C *c2;
|
|
|
|
|
2017-01-20 05:00:13 +08:00
|
|
|
X<int>::X *xi; // expected-error{{qualified reference to 'X' is a constructor name rather than a type}}
|
|
|
|
X<float>::X *xf; // expected-error{{qualified reference to 'X' is a constructor name rather than a type}}
|
2009-03-26 05:17:03 +08:00
|
|
|
|
|
|
|
void test_naming() {
|
2010-04-09 08:35:39 +08:00
|
|
|
c1 = c2; // expected-error{{assigning to 'X<int>::C *' from incompatible type 'X<float>::C *'}}
|
|
|
|
xi = xf; // expected-error{{assigning to 'X<int>::X<int> *' from incompatible type 'X<float>::X<float> *'}}
|
2009-03-26 05:17:03 +08:00
|
|
|
// FIXME: error above doesn't print the type X<int>::X cleanly!
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_instantiation(X<double>::C *x,
|
|
|
|
X<float>::D::E *e,
|
|
|
|
X<float>::D::F *f) {
|
|
|
|
double &dr = x->foo();
|
|
|
|
float &fr = e->bar();
|
2010-03-10 19:27:22 +08:00
|
|
|
f->foo(); // expected-error{{implicit instantiation of undefined member 'X<float>::D::F'}}
|
2009-03-26 05:17:03 +08:00
|
|
|
|
|
|
|
}
|
2009-03-26 05:23:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
X<void>::C *c3; // okay
|
|
|
|
X<void>::D::E *e1; // okay
|
2010-03-10 19:27:22 +08:00
|
|
|
X<void>::D::E e2; // expected-note{{in instantiation of member class 'X<void>::D::E' requested here}}
|
2009-12-16 06:29:06 +08:00
|
|
|
|
|
|
|
// Redeclarations.
|
|
|
|
namespace test1 {
|
|
|
|
template <typename T> struct Registry {
|
2010-04-10 03:03:51 +08:00
|
|
|
struct node;
|
2009-12-16 06:29:06 +08:00
|
|
|
static node *Head;
|
2010-04-10 03:03:51 +08:00
|
|
|
struct node {
|
2009-12-16 06:29:06 +08:00
|
|
|
node(int v) { Head = this; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
void test() {
|
|
|
|
Registry<int>::node node(0);
|
|
|
|
}
|
|
|
|
}
|
2010-03-27 05:56:38 +08:00
|
|
|
|
|
|
|
// Redeclarations during explicit instantiations.
|
|
|
|
namespace test2 {
|
|
|
|
template <typename T> class A {
|
|
|
|
class Foo;
|
|
|
|
class Foo {
|
|
|
|
int foo();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
template class A<int>;
|
|
|
|
|
|
|
|
template <typename T> class B {
|
|
|
|
class Foo;
|
|
|
|
class Foo {
|
2010-04-10 03:03:51 +08:00
|
|
|
public:
|
2010-03-27 05:56:38 +08:00
|
|
|
typedef int X;
|
|
|
|
};
|
|
|
|
typename Foo::X x;
|
|
|
|
};
|
|
|
|
template class B<int>;
|
|
|
|
|
|
|
|
template <typename T> class C {
|
|
|
|
class Foo;
|
|
|
|
};
|
|
|
|
template <typename T> class C<T>::Foo {
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
template class C<int>;
|
|
|
|
}
|
2011-07-02 03:46:12 +08:00
|
|
|
|
|
|
|
namespace AliasTagDef {
|
|
|
|
template<typename T>
|
|
|
|
struct F {
|
2016-04-14 04:00:45 +08:00
|
|
|
using S = struct U {
|
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
// expected-warning@-2 {{alias declarations are a C++11 extension}}
|
|
|
|
#endif
|
2011-07-02 03:46:12 +08:00
|
|
|
T g() {
|
|
|
|
return T();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
int m = F<int>::S().g();
|
|
|
|
int n = F<int>::U().g();
|
|
|
|
}
|
2011-11-08 01:33:42 +08:00
|
|
|
|
|
|
|
namespace rdar10397846 {
|
|
|
|
template<int I> struct A
|
|
|
|
{
|
|
|
|
struct B
|
|
|
|
{
|
2016-04-14 04:00:45 +08:00
|
|
|
struct C { C() { int *ptr = I; } };
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
// expected-error@-2 {{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
|
|
|
|
#else
|
|
|
|
// expected-warning@-4 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}}
|
|
|
|
#endif
|
|
|
|
// expected-error@-6 {{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
|
2011-11-08 01:33:42 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template<int N> void foo()
|
|
|
|
{
|
2012-08-09 01:33:31 +08:00
|
|
|
class A<N>::B::C X; // expected-note 2 {{in instantiation of member function}}
|
2011-11-08 01:33:42 +08:00
|
|
|
int A<N+1>::B::C::*member = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bar()
|
|
|
|
{
|
2012-08-09 01:33:31 +08:00
|
|
|
foo<0>(); // expected-note{{in instantiation of function template}}
|
2011-11-08 01:33:42 +08:00
|
|
|
foo<1>(); // expected-note{{in instantiation of function template}}
|
|
|
|
}
|
|
|
|
}
|