diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -5466,6 +5466,9 @@ Deduced.end()); Sema::InstantiatingTemplate Inst(S, Info.getLocation(), P2, DeducedArgs, Info); + if (Inst.isInvalid()) + return false; + auto *TST1 = T1->castAs(); bool AtLeastAsSpecialized; S.runWithSufficientStackSpace(Info.getLocation(), [&] { diff --git a/clang/test/SemaCXX/template-specialization-fatal.cpp b/clang/test/SemaCXX/template-specialization-fatal.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/template-specialization-fatal.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s +// Verify clang doesn't assert()-fail on template specialization happening after +// fatal error. + +#include "not_found.h" // expected-error {{'not_found.h' file not found}} + +template +struct foo {}; + +template +struct foo(0)(static_cast(0)()))> {};