Skip to content

Commit ddfbdbf

Browse files
committed
[clang] Do not crash on template specialization following a fatal error
There was a missing isInvalid() check leading to an attempt to instantiate template with an empty instantiation stack. Differential Revision: https://reviews.llvm.org/D100675
1 parent 83b8f8d commit ddfbdbf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5466,6 +5466,9 @@ static bool isAtLeastAsSpecializedAs(Sema &S, QualType T1, QualType T2,
54665466
Deduced.end());
54675467
Sema::InstantiatingTemplate Inst(S, Info.getLocation(), P2, DeducedArgs,
54685468
Info);
5469+
if (Inst.isInvalid())
5470+
return false;
5471+
54695472
auto *TST1 = T1->castAs<TemplateSpecializationType>();
54705473
bool AtLeastAsSpecialized;
54715474
S.runWithSufficientStackSpace(Info.getLocation(), [&] {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only %s
2+
// Verify clang doesn't assert()-fail on template specialization happening after
3+
// fatal error.
4+
5+
#include "not_found.h" // expected-error {{'not_found.h' file not found}}
6+
7+
template <class A, class B, class = void>
8+
struct foo {};
9+
10+
template <class A, class B>
11+
struct foo<A, B, decltype(static_cast<void (*)(B)>(0)(static_cast<A (*)()>(0)()))> {};

0 commit comments

Comments
 (0)