summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-05-14 00:28:11 +0000
committerDouglas Gregor <dgregor@apple.com>2009-05-14 00:28:11 +0000
commit2ec748cd5a66e0d8ac3c83887e5014f81e95204c (patch)
tree8028813c3ecd1d35a53eef3be7b1755a9c76a1cb /clang/test
parent0e78566e0207a4cfe8a512ea667f90399f2b255a (diff)
downloadbcm5719-llvm-2ec748cd5a66e0d8ac3c83887e5014f81e95204c.tar.gz
bcm5719-llvm-2ec748cd5a66e0d8ac3c83887e5014f81e95204c.zip
Implement explicit instantiations of member classes of class templates, e.g.,
template<typename T> struct X { struct Inner; }; template struct X<int>::Inner; This change is larger than it looks because it also fixes some a problem with nested-name-specifiers and tags. We weren't requiring the DeclContext associated with the scope specifier of a tag to be complete. Therefore, when looking for something like "struct X<int>::Inner", we weren't instantiating X<int>. This, naturally, uncovered a problem with member pointers, where we were requiring the left-hand side of a member pointer access expression (e.g., x->*) to be a complete type. However, this is wrong: the semantics of this expression does not require a complete type (EDG agrees). Stuart vouched for me. Blame him. llvm-svn: 71756
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/member-pointer.cpp4
-rw-r--r--clang/test/SemaTemplate/instantiate-complete.cpp8
-rw-r--r--clang/test/SemaTemplate/instantiate-typedef.cpp3
-rw-r--r--clang/test/SemaTemplate/temp_explicit.cpp38
4 files changed, 46 insertions, 7 deletions
diff --git a/clang/test/SemaCXX/member-pointer.cpp b/clang/test/SemaCXX/member-pointer.cpp
index 1a663f6e1cc..cfe4f75dd17 100644
--- a/clang/test/SemaCXX/member-pointer.cpp
+++ b/clang/test/SemaCXX/member-pointer.cpp
@@ -80,7 +80,7 @@ void g() {
void (HasMembers::*pmd)() = &HasMembers::d;
}
-struct Incomplete; // expected-note{{forward declaration}}
+struct Incomplete;
void h() {
HasMembers hm, *phm = &hm;
@@ -115,7 +115,7 @@ void h() {
Incomplete *inc;
int Incomplete::*pii = 0;
- (void)inc->*pii; // expected-error {{right hand operand is a pointer to member of incomplete type 'struct Incomplete'}}
+ (void)(inc->*pii); // okay
}
struct OverloadsPtrMem
diff --git a/clang/test/SemaTemplate/instantiate-complete.cpp b/clang/test/SemaTemplate/instantiate-complete.cpp
index 7b4373538d2..babc55217a9 100644
--- a/clang/test/SemaTemplate/instantiate-complete.cpp
+++ b/clang/test/SemaTemplate/instantiate-complete.cpp
@@ -11,8 +11,7 @@ struct X {
// expected-error{{data member instantiated with function type 'int (int)'}} \
// expected-error{{data member instantiated with function type 'char (char)'}} \
// expected-error{{data member instantiated with function type 'short (short)'}} \
- // expected-error{{data member instantiated with function type 'float (float)'}} \
- // expected-error{{data member instantiated with function type 'long (long)'}}
+ // expected-error{{data member instantiated with function type 'float (float)'}}
};
X<int> f() { return 0; }
@@ -41,7 +40,8 @@ void test_new() {
}
void test_memptr(X<long> *p1, long X<long>::*pm1,
- X<long(long)> *p2, long (X<long(long)>::*pm2)(long)) {
+ X<long(long)> *p2,
+ long (X<long(long)>::*pm2)(long)) {
(void)(p1->*pm1);
- (void)(p2->*pm2); // expected-note{{in instantiation of template class 'struct X<long (long)>' requested here}}
+ (void)((p2->*pm2)(0));
}
diff --git a/clang/test/SemaTemplate/instantiate-typedef.cpp b/clang/test/SemaTemplate/instantiate-typedef.cpp
index c1355fca8d5..d30309cc86c 100644
--- a/clang/test/SemaTemplate/instantiate-typedef.cpp
+++ b/clang/test/SemaTemplate/instantiate-typedef.cpp
@@ -11,5 +11,6 @@ add_pointer<float>::type test2(int * ptr) {
return ptr; // expected-error{{incompatible type returning 'int *', expected 'add_pointer<float>::type' (aka 'float *')}}
}
-add_pointer<int&>::type // expected-note{{in instantiation of template class 'struct add_pointer<int &>' requested here}} expected-error {{unknown type name 'type'}}
+add_pointer<int&>::type // expected-note{{in instantiation of template class 'struct add_pointer<int &>' requested here}} \
+// expected-error {{unknown type name 'type'}}
test3();
diff --git a/clang/test/SemaTemplate/temp_explicit.cpp b/clang/test/SemaTemplate/temp_explicit.cpp
index 0b96c73c1f2..6394f1daf47 100644
--- a/clang/test/SemaTemplate/temp_explicit.cpp
+++ b/clang/test/SemaTemplate/temp_explicit.cpp
@@ -71,3 +71,41 @@ void f3(X4<int&>::Inner); // okay, Inner::VeryInner, not instantiated
template struct X4<int&>; // expected-note{{instantiation}}
template struct X4<float&>; // expected-note{{instantiation}}
+
+// Check explicit instantiation of member classes
+namespace N2 {
+
+template<typename T>
+struct X5 {
+ struct Inner1 {
+ void f(T&);
+ };
+
+ struct Inner2 {
+ struct VeryInner { // expected-note 2{{instantiation}}
+ void g(T*); // expected-error 2{{pointer to a reference}}
+ };
+ };
+};
+
+}
+
+template struct N2::X5<void>::Inner2;
+
+using namespace N2;
+template struct X5<int&>::Inner2; // expected-note{{instantiation}}
+
+void f4(X5<float&>::Inner2);
+template struct X5<float&>::Inner2; // expected-note{{instantiation}}
+
+namespace N3 {
+ template struct N2::X5<int>::Inner2;
+}
+
+struct X6 {
+ struct Inner { // expected-note{{here}}
+ void f();
+ };
+};
+
+template struct X6::Inner; // expected-error{{non-templated}}
OpenPOWER on IntegriCloud