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
diff --git a/clang/test/SemaCXX/member-pointer.cpp b/clang/test/SemaCXX/member-pointer.cpp
index 1a663f6..cfe4f75 100644
--- a/clang/test/SemaCXX/member-pointer.cpp
+++ b/clang/test/SemaCXX/member-pointer.cpp
@@ -80,7 +80,7 @@
   void (HasMembers::*pmd)() = &HasMembers::d;
 }
 
-struct Incomplete; // expected-note{{forward declaration}}
+struct Incomplete;
 
 void h() {
   HasMembers hm, *phm = &hm;
@@ -115,7 +115,7 @@
 
   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 7b43735..babc552 100644
--- a/clang/test/SemaTemplate/instantiate-complete.cpp
+++ b/clang/test/SemaTemplate/instantiate-complete.cpp
@@ -11,8 +11,7 @@
        // 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_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 c1355fc..d30309c 100644
--- a/clang/test/SemaTemplate/instantiate-typedef.cpp
+++ b/clang/test/SemaTemplate/instantiate-typedef.cpp
@@ -11,5 +11,6 @@
   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 0b96c73..6394f1d 100644
--- a/clang/test/SemaTemplate/temp_explicit.cpp
+++ b/clang/test/SemaTemplate/temp_explicit.cpp
@@ -71,3 +71,41 @@
 
 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}}