https://github.com/knightXun updated https://github.com/llvm/llvm-project/pull/74885
>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> 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<Derived>::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<TemplateTypeParmDecl>(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 <badgangkil...@gmail.com> 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<Derived>::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<TemplateTypeParmDecl>(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<Derived>::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<TemplateTypeParmDecl>(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 <badgangkil...@gmail.com> Date: Sat, 9 Dec 2023 21:40:36 +0800 Subject: [PATCH 03/14] fx --- clang/include/clang/Basic/DiagnosticParseKinds.td | 2 -- clang/lib/Sema/TreeTransform.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index e46fa69d013b6..6150fc36430ab 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -851,8 +851,6 @@ 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 9fb426c1a044b..82be2c800ff7a 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -13606,8 +13606,6 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { if (conceptParams > 0 && conceptParams == E->getTemplateParameterList()->size()) { - getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(), - diag::err_expected_non_concept_template_parameter); return ExprError(); } } >From 6680a4d1a47d69f37286268106919eafe34d61d9 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sat, 9 Dec 2023 22:44:27 +0800 Subject: [PATCH 04/14] try -to fix --- clang/lib/Sema/TreeTransform.h | 51 ++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 82be2c800ff7a..005e174ea8b1c 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6439,6 +6439,25 @@ QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, Sema::ExpressionEvaluationContextRecord::EK_Decltype); + auto EE = T->getUnderlyingExpr(); + if (EE->isInstantiationDependent()) { + // Check the number of the Concept template parameters + size_t conceptParams = 0; + if (auto lambdaExpr = dyn_cast<LambdaExpr>(EE)) { + for (auto P : *lambdaExpr->getTemplateParameterList()) { + const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (CD && CD->hasTypeConstraint()) { + conceptParams++; + } + } + + if (conceptParams > 0 && + conceptParams == lambdaExpr->getTemplateParameterList()->size()) { + return QualType(); + } + } + } + ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); if (E.isInvalid()) return QualType(); @@ -13594,21 +13613,23 @@ TreeTransform<Derived>::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<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; - } - } - - if (conceptParams > 0 && - conceptParams == E->getTemplateParameterList()->size()) { - return ExprError(); - } - } + // 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<TemplateTypeParmDecl>(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 >From 8f1365b8ef8137cf654b416f4945a70769c104ee Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sat, 9 Dec 2023 23:00:44 +0800 Subject: [PATCH 05/14] try -to fix --- clang/lib/Sema/TreeTransform.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 005e174ea8b1c..24470e5e689d9 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6444,16 +6444,18 @@ QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, // Check the number of the Concept template parameters size_t conceptParams = 0; if (auto lambdaExpr = dyn_cast<LambdaExpr>(EE)) { - for (auto P : *lambdaExpr->getTemplateParameterList()) { - const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; + if (lambdaExpr->getTemplateParameterList()) { + for (auto P : *lambdaExpr->getTemplateParameterList()) { + const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (CD && CD->hasTypeConstraint()) { + conceptParams++; + } } - } - if (conceptParams > 0 && - conceptParams == lambdaExpr->getTemplateParameterList()->size()) { - return QualType(); + if (conceptParams > 0 && + conceptParams == lambdaExpr->getTemplateParameterList()->size()) { + return QualType(); + } } } } >From a77a441334e01fc35ba7c64ca3012f2bd3bb33aa Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 01:07:54 +0800 Subject: [PATCH 06/14] try -to fix --- clang/lib/Sema/SemaTemplateDeduction.cpp | 18 +++++++++++ clang/lib/Sema/TreeTransform.h | 40 +++++++++++++----------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 699e0985e595b..9180ab16fdbc6 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3646,6 +3646,24 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( if (CheckNonDependent()) return TDK_NonDependentConversionFailure; + if (FunctionTemplate->getTemplateParameters()) { + // Check the number of the Concept template parameters + size_t conceptParams = 0; + for (auto P : *FunctionTemplate->getTemplateParameters()) { + const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (CD && CD->hasTypeConstraint()) { + conceptParams++; + } + } + + if (conceptParams > 0 && + conceptParams == FunctionTemplate->getTemplateParameters()->size()) { + // getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(), + // diag::err_expected_non_concept_template_parameter); + return TDK_SubstitutionFailure; + } + } + // Form the template argument list from the deduced template arguments. TemplateArgumentList *SugaredDeducedArgumentList = TemplateArgumentList::CreateCopy(Context, SugaredBuilder); diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 24470e5e689d9..e263cc1596c82 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6439,26 +6439,28 @@ QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, Sema::ExpressionEvaluationContextRecord::EK_Decltype); - auto EE = T->getUnderlyingExpr(); - if (EE->isInstantiationDependent()) { - // Check the number of the Concept template parameters - size_t conceptParams = 0; - if (auto lambdaExpr = dyn_cast<LambdaExpr>(EE)) { - if (lambdaExpr->getTemplateParameterList()) { - for (auto P : *lambdaExpr->getTemplateParameterList()) { - const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; - } - } + // while(auto EE = T->getUnderlyingExpr()){} + // if (EE->isInstantiationDependent()) { - if (conceptParams > 0 && - conceptParams == lambdaExpr->getTemplateParameterList()->size()) { - return QualType(); - } - } - } - } + // // Check the number of the Concept template parameters + // size_t conceptParams = 0; + // if (auto lambdaExpr = dyn_cast<LambdaExpr>(EE)) { + // if (lambdaExpr->getTemplateParameterList()) { + // for (auto P : *lambdaExpr->getTemplateParameterList()) { + // const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + // if (CD && CD->hasTypeConstraint()) { + // conceptParams++; + // } + // } + + // if (conceptParams > 0 && + // conceptParams == lambdaExpr->getTemplateParameterList()->size()) + // { + // return QualType(); + // } + // } + // } + // } ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); if (E.isInvalid()) >From b1915bd4c8c751831e7824234e6eabe87dd599b5 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 02:08:45 +0800 Subject: [PATCH 07/14] try -to fix --- clang/lib/Sema/SemaTemplateDeduction.cpp | 34 +++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 9180ab16fdbc6..cab0c1c74e4e2 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3646,24 +3646,6 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( if (CheckNonDependent()) return TDK_NonDependentConversionFailure; - if (FunctionTemplate->getTemplateParameters()) { - // Check the number of the Concept template parameters - size_t conceptParams = 0; - for (auto P : *FunctionTemplate->getTemplateParameters()) { - const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; - } - } - - if (conceptParams > 0 && - conceptParams == FunctionTemplate->getTemplateParameters()->size()) { - // getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(), - // diag::err_expected_non_concept_template_parameter); - return TDK_SubstitutionFailure; - } - } - // Form the template argument list from the deduced template arguments. TemplateArgumentList *SugaredDeducedArgumentList = TemplateArgumentList::CreateCopy(Context, SugaredBuilder); @@ -3719,6 +3701,22 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( return TDK_SubstitutionFailure; } + if (FunctionTemplate->getTemplateParameters()) { + // Check the number of the Concept template parameters + size_t conceptParams = 0; + for (auto P : *FunctionTemplate->getTemplateParameters()) { + const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (CD && CD->hasTypeConstraint()) { + conceptParams++; + } + } + + if (FunctionTemplate->getTemplateParameters()->size() - conceptParams != + Info.getNumExplicitArgs()) { + return TDK_SubstitutionFailure; + } + } + // C++2a [temp.deduct]p5 // [...] When all template arguments have been deduced [...] all uses of // template parameters [...] are replaced with the corresponding deduced >From 63845ce44235b70f00796cb14b808e56207d7f4a Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 02:17:56 +0800 Subject: [PATCH 08/14] try -to fix --- clang/lib/Sema/SemaTemplateDeduction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index cab0c1c74e4e2..a33e5a4e67ab7 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3711,8 +3711,8 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( } } - if (FunctionTemplate->getTemplateParameters()->size() - conceptParams != - Info.getNumExplicitArgs()) { + if (FunctionTemplate->getTemplateParameters()->size() == conceptParams && + Info.getNumExplicitArgs() > 0) { return TDK_SubstitutionFailure; } } >From 773f617f71896bde8ea3945041adddba42f39d15 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 02:32:02 +0800 Subject: [PATCH 09/14] try -to fix --- clang/lib/Sema/SemaTemplateDeduction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index a33e5a4e67ab7..41c1587a793cd 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3711,7 +3711,8 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( } } - if (FunctionTemplate->getTemplateParameters()->size() == conceptParams && + if (conceptParams > 0 && + FunctionTemplate->getTemplateParameters()->size() == conceptParams && Info.getNumExplicitArgs() > 0) { return TDK_SubstitutionFailure; } >From a55f07b9b469178177d8d0f6574e12e3be7a446f Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 04:55:51 +0800 Subject: [PATCH 10/14] try -to fix --- clang/lib/Sema/SemaTemplateDeduction.cpp | 30 ++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 41c1587a793cd..6d3f2182e55dd 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3222,7 +3222,20 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments( *FunctionType = Function->getType(); return TDK_Success; } + // if (FunctionTemplate->getTemplateParameterList()) { + // Check the number of the Concept template parameters + size_t conceptParams = 0; + for (auto P : *TemplateParams) { + const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (CD && CD->hasTypeConstraint()) { + conceptParams++; + } + } + if (conceptParams == TemplateParams->size()) { + return TDK_Success; + } + // } // Unevaluated SFINAE context. EnterExpressionEvaluationContext Unevaluated( *this, Sema::ExpressionEvaluationContext::Unevaluated); @@ -3701,23 +3714,6 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( return TDK_SubstitutionFailure; } - if (FunctionTemplate->getTemplateParameters()) { - // Check the number of the Concept template parameters - size_t conceptParams = 0; - for (auto P : *FunctionTemplate->getTemplateParameters()) { - const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; - } - } - - if (conceptParams > 0 && - FunctionTemplate->getTemplateParameters()->size() == conceptParams && - Info.getNumExplicitArgs() > 0) { - return TDK_SubstitutionFailure; - } - } - // C++2a [temp.deduct]p5 // [...] When all template arguments have been deduced [...] all uses of // template parameters [...] are replaced with the corresponding deduced >From 0634a11888ca35695188cf8b97a63bde61875de1 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 06:09:08 +0800 Subject: [PATCH 11/14] try -to fix --- clang/lib/Sema/SemaConcept.cpp | 13 +++++++++++++ clang/lib/Sema/SemaTemplateDeduction.cpp | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 719c6aab74e01..65acb4581611e 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -917,6 +917,19 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( LambdaScopeForCallOperatorInstantiationRAII LambdaScope( *this, const_cast<FunctionDecl *>(Decl), *MLTAL, Scope); + // Check the number of the Concept template parameters + size_t conceptParams = 0; + for (auto P : *Template->getTemplateParameters()) { + const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (CD && CD->hasTypeConstraint()) { + conceptParams++; + } + } + + if (conceptParams > 0 && conceptParams == TemplateArgs.size()) { + return false; + } + llvm::SmallVector<Expr *, 1> Converted; return CheckConstraintSatisfaction(Template, TemplateAC, Converted, *MLTAL, PointOfInstantiation, Satisfaction); diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 6d3f2182e55dd..699e0985e595b 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3222,20 +3222,7 @@ Sema::TemplateDeductionResult Sema::SubstituteExplicitTemplateArguments( *FunctionType = Function->getType(); return TDK_Success; } - // if (FunctionTemplate->getTemplateParameterList()) { - // Check the number of the Concept template parameters - size_t conceptParams = 0; - for (auto P : *TemplateParams) { - const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; - } - } - if (conceptParams == TemplateParams->size()) { - return TDK_Success; - } - // } // Unevaluated SFINAE context. EnterExpressionEvaluationContext Unevaluated( *this, Sema::ExpressionEvaluationContext::Unevaluated); >From 623dd4257fc8c92a6160dedbbc316065b767a400 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 06:19:17 +0800 Subject: [PATCH 12/14] try -to fix --- clang/lib/Sema/SemaConcept.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 65acb4581611e..9302cdcd9870e 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -918,18 +918,13 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( *this, const_cast<FunctionDecl *>(Decl), *MLTAL, Scope); // Check the number of the Concept template parameters - size_t conceptParams = 0; - for (auto P : *Template->getTemplateParameters()) { - const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (CD && CD->hasTypeConstraint()) { - conceptParams++; + for (auto P : TemplateAC) { + // const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + if (!P->isTypeDependent()) { + return false; } } - if (conceptParams > 0 && conceptParams == TemplateArgs.size()) { - return false; - } - llvm::SmallVector<Expr *, 1> Converted; return CheckConstraintSatisfaction(Template, TemplateAC, Converted, *MLTAL, PointOfInstantiation, Satisfaction); >From 1df66900385bb3351b4197fc7ecbefbed7b30b35 Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 06:26:32 +0800 Subject: [PATCH 13/14] try -to fix --- clang/lib/Sema/SemaConcept.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 9302cdcd9870e..d142207b40e9f 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -920,7 +920,7 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( // Check the number of the Concept template parameters for (auto P : TemplateAC) { // const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (!P->isTypeDependent()) { + if (!P->isValueDependent()) { return false; } } >From 8d34d03d1135c00e9db524a574c556cedfb1e4ae Mon Sep 17 00:00:00 2001 From: knightXun <badgangkil...@gmail.com> Date: Sun, 10 Dec 2023 08:34:55 +0800 Subject: [PATCH 14/14] try -to fix --- clang/lib/Sema/SemaConcept.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index d142207b40e9f..efcf504ebf20b 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -16,6 +16,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/ExprConcepts.h" #include "clang/AST/RecursiveASTVisitor.h" +#include "clang/AST/Type.h" #include "clang/Basic/OperatorPrecedence.h" #include "clang/Sema/EnterExpressionEvaluationContext.h" #include "clang/Sema/Initialization.h" @@ -917,13 +918,27 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( LambdaScopeForCallOperatorInstantiationRAII LambdaScope( *this, const_cast<FunctionDecl *>(Decl), *MLTAL, Scope); - // Check the number of the Concept template parameters - for (auto P : TemplateAC) { - // const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); - if (!P->isValueDependent()) { - return false; + auto parent = Decl->getParent(); + while (parent) { + if (auto *TD = dyn_cast<TypeDecl>(parent)) { + for (auto P : TemplateAC) { + if (P->isValueDependent()) { + return false; + } + } } + parent = parent->getParent(); + // if (parent->getDeclKind() == Decl::Decla) { + + // } } + // Check the number of the Concept template parameters + // for (auto P : TemplateAC) { + // // const TemplateTypeParmDecl *CD = dyn_cast<TemplateTypeParmDecl>(P); + // if (!P->isValueDependent()) { + // return false; + // } + // } llvm::SmallVector<Expr *, 1> Converted; return CheckConstraintSatisfaction(Template, TemplateAC, Converted, *MLTAL, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits