llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: flyingcat  (knightXun)

<details>
<summary>Changes</summary>

Check that the number of non-concept template parameters is greater than zero 
during lambda template instantiation to aviod panic Fix issue: 
https://github.com/llvm/llvm-project/issues/70601

---
Full diff: https://github.com/llvm/llvm-project/pull/74885.diff


2 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/lib/Sema/TreeTransform.h (+14) 


``````````diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e46fa69d013b61 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -851,6 +851,8 @@ def err_friend_explicit_instantiation : Error<
 def err_explicit_instantiation_enum : Error<
   "enumerations cannot be explicitly instantiated">;
 def err_expected_template_parameter : Error<"expected template parameter">;
+def err_expected_non_concept_template_parameter : Error<
+  "expected non-concept template parameter">;
 def err_empty_requires_expr : Error<
   "a requires expression must contain at least one requirement">;
 def err_requires_expr_parameter_list_ellipsis : Error<
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1ad843d0bf4e0c..110024a377128b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,20 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr 
*E) {
     getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
                                                         TPL);
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+    const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P);
+    if (CD && CD->hasTypeConstraint()) {
+      conceptParams++;
+    }
+  }
+
+  if (conceptParams == E->getTemplateParameterList()->size()) {
+    getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+                   diag::err_expected_non_concept_template_parameter);
+    return ExprError();
+  }
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
   // it introduces a mapping of the original to the newly created

``````````

</details>


https://github.com/llvm/llvm-project/pull/74885
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to