From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- .../test/SemaTemplate/instantiate-member-class.cpp | 142 +++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 clang/test/SemaTemplate/instantiate-member-class.cpp (limited to 'clang/test/SemaTemplate/instantiate-member-class.cpp') diff --git a/clang/test/SemaTemplate/instantiate-member-class.cpp b/clang/test/SemaTemplate/instantiate-member-class.cpp new file mode 100644 index 0000000..bb64276 --- /dev/null +++ b/clang/test/SemaTemplate/instantiate-member-class.cpp @@ -0,0 +1,142 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace PR8965 { + template + struct X { + typedef int type; + + T field; // expected-note{{in instantiation of member class}} + }; + + template + struct Y { + struct Inner; + + typedef typename X::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'; it has not yet been instantiated}} + }; + }; + + Y y; // expected-note{{in instantiation of template class}} +} + +template +class X { +public: + struct C { T &foo(); }; + + struct D { + struct E { T &bar(); }; // expected-error{{cannot form a reference to 'void'}} + struct F; // expected-note{{member is declared here}} + }; +}; + +X::C *c1; +X::C *c2; + +X::X *xi; // expected-error{{qualified reference to 'X' is a constructor name rather than a type wherever a constructor can be declared}} +X::X *xf; // expected-error{{qualified reference to 'X' is a constructor name rather than a type wherever a constructor can be declared}} + +void test_naming() { + c1 = c2; // expected-error{{assigning to 'X::C *' from incompatible type 'X::C *'}} + xi = xf; // expected-error{{assigning to 'X::X *' from incompatible type 'X::X *'}} + // FIXME: error above doesn't print the type X::X cleanly! +} + +void test_instantiation(X::C *x, + X::D::E *e, + X::D::F *f) { + double &dr = x->foo(); + float &fr = e->bar(); + f->foo(); // expected-error{{implicit instantiation of undefined member 'X::D::F'}} + +} + + +X::C *c3; // okay +X::D::E *e1; // okay +X::D::E e2; // expected-note{{in instantiation of member class 'X::D::E' requested here}} + +// Redeclarations. +namespace test1 { + template struct Registry { + struct node; + static node *Head; + struct node { + node(int v) { Head = this; } + }; + }; + void test() { + Registry::node node(0); + } +} + +// Redeclarations during explicit instantiations. +namespace test2 { + template class A { + class Foo; + class Foo { + int foo(); + }; + }; + template class A; + + template class B { + class Foo; + class Foo { + public: + typedef int X; + }; + typename Foo::X x; + class Foo; + }; + template class B; + + template class C { + class Foo; + class Foo; + }; + template class C::Foo { + int x; + }; + template class C; +} + +namespace AliasTagDef { + template + struct F { + using S = struct U { // expected-warning {{C++11}} + T g() { + return T(); + } + }; + }; + + int m = F::S().g(); + int n = F::U().g(); +} + +namespace rdar10397846 { + template struct A + { + struct B + { + struct C { C() { int *ptr = I; } }; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} + }; + }; + + template void foo() + { + class A::B::C X; // expected-note{{in instantiation of member function}} + int A::B::C::*member = 0; + } + + void bar() + { + foo<0>(); + foo<1>(); // expected-note{{in instantiation of function template}} + } +} -- cgit v1.2.3