[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-11 Thread via cfe-commits

https://github.com/knightXun closed 
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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-11 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/19] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/19] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/19] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-11 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/18] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/18] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/18] fx

---
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-10 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/17] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/17] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/17] fx

---
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-10 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/16] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/16] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/16] fx

---
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-10 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 44dc1e0baae7c4b8a02ba06dcf396d3d452aa873 
a14cfc5f15fcddd4b89155c4f3f58a21c27140c4 -- clang/lib/Sema/SemaConcept.cpp 
clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/Sema/TreeTransform.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f8556b5d9a..18f038025d 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -932,7 +932,7 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
 
   //   // }
   // }
-  
+
   // Check the number of the Concept template parameters
   // for (auto P : TemplateAC) {
   //   // const TemplateTypeParmDecl *CD = dyn_cast(P);
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 10e93f8555..7c3702e006 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3614,10 +3614,10 @@ Sema::TemplateDeductionResult 
Sema::FinishTemplateArgumentDeduction(
   SFINAETrap Trap(*this);
 
   auto *Method = dyn_cast(FunctionTemplate);
-  for(auto arg: Deduced) {
+  for (auto arg : Deduced) {
 auto ty = arg.getAsType();
-if ( ty->isBuiltinType() ) {
-return TDK_SubstitutionFailure;
+if (ty->isBuiltinType()) {
+  return TDK_SubstitutionFailure;
 }
   }
   // Enter a new template instantiation context while we instantiate the

``




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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-10 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/15] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/15] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/15] fx

---
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-10 Thread via cfe-commits

knightXun wrote:

> This needs at least one test and a Release note.
> 
> I expect the code form the issue to be well-formed: 
> https://godbolt.org/z/bhdfG34xc
> 
> So I am curious why you are adding the diagnostic for?

thanks for the hit! 

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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/14] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/14] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/14] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/13] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/13] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/13] fx

---
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/12] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/12] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/12] fx

---
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/11] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/11] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/11] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/10] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/10] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/10] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/9] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/9] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/9] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/8] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/8] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/8] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/7] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/7] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/7] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 --
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/6] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/6] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/6] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/5] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/5] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/5] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 --
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/4] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/4] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/4] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/3] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/3] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 3/3] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 --
 

[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-09 Thread via cfe-commits

knightXun wrote:

> This needs at least one test and a Release note.
> 
> I expect the code form the issue to be well-formed: 
> https://godbolt.org/z/bhdfG34xc
> 
> So I am curious why you are adding the diagnostic for?

but the lambda template param is unknown, how can the template instantiator 
deduce the real type?

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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This needs at least one test and a Release note.

I expect the code form the issue to be well-formed: 
https://godbolt.org/z/bhdfG34xc

So I am curious why you are adding the diagnostic for?

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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/2] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 2/2] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+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
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH] [Clang][Sema] Check the number of lambda non-concept tempate
 parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 1/2] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From db02522026418a1a0ac2b34e24a29596dae05f9f Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 06:56:06 +0800
Subject: [PATCH 2/2] fix ut

---
 clang/lib/Sema/TreeTransform.h | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..fa0b9a0ca7d69f 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,21 +13662,21 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
+  // // Check the number of the Concept template parameters
+  // size_t conceptParams = 0;
+  // for (auto P : *E->getTemplateParameterList()) {
+  //   const TemplateTypeParmDecl *CD = dyn_cast(P);
+  //   if (CD && CD->hasTypeConstraint()) {
+  // conceptParams++;
+  //   }
+  // }
+
+  // if (conceptParams > 0 &&
+  // conceptParams == E->getTemplateParameterList()->size()) {
+  //   getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+  //  diag::err_expected_non_concept_template_parameter);
+  //   return ExprError();
+  // }
 
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH] [Clang][Sema] Check the number of lambda non-concept tempate
 parameters 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

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

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..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 4b5f4c6a15e84a9c3025a241cc5e11ad768dfdda Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH] [Clang][Sema] Check the number of lambda non-concept tempate
 parameters 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

---
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Sema/TreeTransform.h| 15 +++
 2 files changed, 17 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..b22f8af3b12c2 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,21 @@ TreeTransform::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(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  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

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: flyingcat  (knightXun)


Changes

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::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(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

``




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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-08 Thread via cfe-commits

https://github.com/knightXun created 
https://github.com/llvm/llvm-project/pull/74885

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

>From 05588ae4cd3e0a55f946c9d109470afbfd91c1be Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH] [Clang][Sema] Check the number of lambda non-concept tempate
 parameters 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

---
 clang/include/clang/Basic/DiagnosticParseKinds.td |  2 ++
 clang/lib/Sema/TreeTransform.h| 14 ++
 2 files changed, 16 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 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 1ad843d0bf4e0..110024a377128 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,20 @@ TreeTransform::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(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

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits