[clang] 440fffa - [Clang][Concepts] Avoid substituting into constraints for invalid TemplateDecls (#75697)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 04:17:06 PDT 2024
Author: Younan Zhang
Date: 2024-07-17T19:17:01+08:00
New Revision: 440fffad7e7231fab766c6e00e47a39ad5a9b95e
URL: https://github.com/llvm/llvm-project/commit/440fffad7e7231fab766c6e00e47a39ad5a9b95e
DIFF: https://github.com/llvm/llvm-project/commit/440fffad7e7231fab766c6e00e47a39ad5a9b95e.diff
LOG: [Clang][Concepts] Avoid substituting into constraints for invalid TemplateDecls (#75697)
Fixes https://github.com/llvm/llvm-project/issues/73885.
Substituting into constraints for invalid TemplateDecls might still
yield dependent expressions and end up crashing later in evaluation.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaConcept.cpp
clang/test/SemaTemplate/instantiate-requires-expr.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c0d1635d2756..6dc45956a9afb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 84c5753a46ac3..9e16b67284be4 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -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
diff --git a/clang/test/SemaTemplate/instantiate-requires-expr.cpp b/clang/test/SemaTemplate/instantiate-requires-expr.cpp
index 516708bf4c875..20a19d731ae16 100644
--- a/clang/test/SemaTemplate/instantiate-requires-expr.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-expr.cpp
@@ -227,3 +227,13 @@ struct r6 {};
using r6i = r6<int>;
// expected-error at -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
More information about the cfe-commits
mailing list