Skip to content

Commit 440fffa

Browse files
authored
[Clang][Concepts] Avoid substituting into constraints for invalid TemplateDecls (#75697)
Fixes #73885. Substituting into constraints for invalid TemplateDecls might still yield dependent expressions and end up crashing later in evaluation.
1 parent 8156be6 commit 440fffa

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ Bug Fixes to C++ Support
10421042
- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043).
10431043
- Clang now diagnoses explicit object parameters in member pointers and other contexts where they should not appear.
10441044
Fixes (#GH85992).
1045+
- Fixed a crash-on-invalid bug involving extraneous template parameter with concept substitution. (#GH73885)
10451046

10461047
Bug Fixes to AST Handling
10471048
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaConcept.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ bool Sema::CheckConstraintSatisfaction(
625625
*this, nullptr, ConstraintExprs, ConvertedConstraints,
626626
TemplateArgsLists, TemplateIDRange, OutSatisfaction);
627627
}
628+
// Invalid templates could make their way here. Substituting them could result
629+
// in dependent expressions.
630+
if (Template->isInvalidDecl()) {
631+
OutSatisfaction.IsSatisfied = false;
632+
return true;
633+
}
628634

629635
// A list of the template argument list flattened in a predictible manner for
630636
// the purposes of caching. The ConstraintSatisfaction type is in AST so it

clang/test/SemaTemplate/instantiate-requires-expr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,13 @@ struct r6 {};
227227

228228
using r6i = r6<int>;
229229
// expected-error@-1 {{constraints not satisfied for class template 'r6' [with T = int]}}
230+
231+
namespace GH73885 {
232+
233+
template <class> // expected-error {{extraneous}}
234+
template <class T> requires(T{})
235+
constexpr bool e_v = true;
236+
237+
static_assert(e_v<bool>);
238+
239+
} // namespace GH73885

0 commit comments

Comments
 (0)