Skip to content

Commit

Permalink
[Clang][Concepts] Avoid substituting into constraints for invalid Tem…
Browse files Browse the repository at this point in the history
…plateDecls (llvm#75697)

Fixes llvm#73885.

Substituting into constraints for invalid TemplateDecls might still
yield dependent expressions and end up crashing later in evaluation.
  • Loading branch information
zyn0217 authored and sgundapa committed Jul 23, 2024
1 parent 3a51ee8 commit 9a21ac1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ Bug Fixes to C++ Support
- Fixed failed assertion when resolving context of defaulted comparison method outside of struct. (#GH96043).
- Clang now diagnoses explicit object parameters in member pointers and other contexts where they should not appear.
Fixes (#GH85992).
- Fixed a crash-on-invalid bug involving extraneous template parameter with concept substitution. (#GH73885)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaConcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,12 @@ bool Sema::CheckConstraintSatisfaction(
*this, nullptr, ConstraintExprs, ConvertedConstraints,
TemplateArgsLists, TemplateIDRange, OutSatisfaction);
}
// Invalid templates could make their way here. Substituting them could result
// in dependent expressions.
if (Template->isInvalidDecl()) {
OutSatisfaction.IsSatisfied = false;
return true;
}

// A list of the template argument list flattened in a predictible manner for
// the purposes of caching. The ConstraintSatisfaction type is in AST so it
Expand Down
10 changes: 10 additions & 0 deletions clang/test/SemaTemplate/instantiate-requires-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,13 @@ struct r6 {};

using r6i = r6<int>;
// expected-error@-1 {{constraints not satisfied for class template 'r6' [with T = int]}}

namespace GH73885 {

template <class> // expected-error {{extraneous}}
template <class T> requires(T{})
constexpr bool e_v = true;

static_assert(e_v<bool>);

} // namespace GH73885

0 comments on commit 9a21ac1

Please sign in to comment.