Propagate the invalid bit from bases to derived template classes.

Fixes PR16292.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184581 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 5e3ced4..9babafe 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1754,6 +1754,10 @@
          Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end();
        Base != BaseEnd; ++Base) {
     if (!Base->getType()->isDependentType()) {
+      if (const CXXRecordDecl *RD = Base->getType()->getAsCXXRecordDecl()) {
+        if (RD->isInvalidDecl())
+          Instantiation->setInvalidDecl();
+      }
       InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(*Base));
       continue;
     }
diff --git a/test/SemaTemplate/derived.cpp b/test/SemaTemplate/derived.cpp
index 7b91f9a..a76b34f 100644
--- a/test/SemaTemplate/derived.cpp
+++ b/test/SemaTemplate/derived.cpp
@@ -28,3 +28,12 @@
     }
   };
 }
+
+namespace PR16292 {
+  class IncompleteClass;  // expected-note{{forward declaration}}
+  class BaseClass {
+    IncompleteClass Foo;  // expected-error{{field has incomplete type}}
+  };
+  template<class T> class DerivedClass : public BaseClass {};
+  void* p = new DerivedClass<void>;
+}