Skip to content

Commit a042fcb

Browse files
authored
[clang] Bailout when the substitution of template parameter mapping is invalid. (#86869)
Fixes #86757 We missed to handle the invalid case when substituting into the parameter mapping of an constraint during normalization. The constructor of `InstantiatingTemplate` will bail out (no `CodeSynthesisContext` will be added to the instantiation stack) if there was a fatal error, consequently we should stop doing any further template instantiations.
1 parent fb8cccf commit a042fcb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ Bug Fixes to C++ Support
458458
- Fix an issue where a namespace alias could be defined using a qualified name (all name components
459459
following the first `::` were ignored).
460460
- Fix an out-of-bounds crash when checking the validity of template partial specializations. (part of #GH86757).
461+
- Fix an issue caused by not handling invalid cases when substituting into the parameter mapping of a constraint. Fixes (#GH86757).
461462

462463
Bug Fixes to AST Handling
463464
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaConcept.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N,
12811281
S, InstLocBegin,
12821282
Sema::InstantiatingTemplate::ParameterMappingSubstitution{}, Concept,
12831283
{InstLocBegin, InstLocEnd});
1284+
if (Inst.isInvalid())
1285+
return true;
12841286
if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
12851287
return true;
12861288

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -std=c++20 -Wfatal-errors -verify %s
2+
3+
template <typename> int a;
4+
template <typename... b> concept c = a<b...>;
5+
template <typename> concept e = c<>;
6+
7+
// must be a fatal error to trigger the crash
8+
undefined; // expected-error {{a type specifier is required for all declarations}}
9+
10+
template <typename d> concept g = e<d>;
11+
template <g> struct h
12+
template <g d>
13+
struct h<d>;

0 commit comments

Comments
 (0)