Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -1939,8 +1939,10 @@ } InstantiatingTemplate Inst(*this, PointOfInstantiation, Instantiation); - if (Inst.isInvalid()) + if (Inst.isInvalid()) { + Instantiation->setInvalidDecl(true); return true; + } // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. Index: test/SemaTemplate/instantiate-explicitly-after-fatal.cpp =================================================================== --- /dev/null +++ test/SemaTemplate/instantiate-explicitly-after-fatal.cpp @@ -0,0 +1,9 @@ +// RUN: not %clang_cc1 -fsyntax-only -std=c++11 -ferror-limit 1 %s 2>&1 | FileCheck %s +unknown_type foo(unknown_type); +// CHECK: fatal error: too many errors emitted, stopping now + +template +class Bar {}; + +extern template class Bar; +template class Bar;