@@ -351,7 +351,11 @@ static std::optional<MultiLevelTemplateArgumentList>
351351SubstitutionInTemplateArguments (
352352 Sema &S, const NormalizedConstraintWithParamMapping &Constraint,
353353 const NamedDecl *Template, MultiLevelTemplateArgumentList MLTAL,
354- llvm::SmallVector<TemplateArgument> &SubstitutedOuterMost) {
354+ llvm::SmallVector<TemplateArgument> &SubstitutedOuterMost,
355+ // FIXME: Having both PackSubstitutionIndex and
356+ // NormalizedConstraintWithParamMapping::getPackSubstitutionIndex is
357+ // confusing
358+ UnsignedOrNone PackSubstitutionIndex) {
355359
356360 Sema::InstantiatingTemplate Inst (
357361 S, Constraint.getBeginLoc (),
@@ -369,7 +373,9 @@ SubstitutionInTemplateArguments(
369373 TemplateArgumentListInfo SubstArgs;
370374 if (Constraint.hasParameterMapping ()) {
371375 Sema::ArgPackSubstIndexRAII SubstIndex (
372- S, Constraint.getPackSubstitutionIndex ());
376+ S, Constraint.getPackSubstitutionIndex ()
377+ ? Constraint.getPackSubstitutionIndex ()
378+ : PackSubstitutionIndex);
373379 if (S.SubstTemplateArgumentsInParameterMapping (
374380 Constraint.getParameterMapping (), MLTAL, SubstArgs) ||
375381 Trap.hasErrorOccurred ())
@@ -405,11 +411,12 @@ static bool calculateConstraintSatisfaction(
405411 llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
406412 std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
407413 SubstitutionInTemplateArguments (S, Constraint, Template, MLTAL,
408- SubstitutedOuterMost);
414+ SubstitutedOuterMost,
415+ PackSubstitutionIndex);
409416 if (!SubstitutedArgs)
410417 return false ;
411418
412- Sema::ArgPackSubstIndexRAII (S, PackSubstitutionIndex);
419+ Sema::ArgPackSubstIndexRAII SubstIndex (S, PackSubstitutionIndex);
413420 ExprResult SubstitutedAtomicExpr =
414421 EvaluateAtomicConstraint (S, Constraint.getConstraintExpr (), Template,
415422 TemplateNameLoc, *SubstitutedArgs, Satisfaction);
@@ -526,7 +533,8 @@ static bool calculateConstraintSatisfaction(
526533 S,
527534 static_cast <const NormalizedConstraintWithParamMapping &>(
528535 FE.getNormalizedPattern ()),
529- Template, MLTAL, SubstitutedOuterMost);
536+ // FIXME: Is PackSubstitutionIndex correct?
537+ Template, MLTAL, SubstitutedOuterMost, S.ArgPackSubstIndex );
530538 if (!SubstitutedArgs)
531539 return false ;
532540
@@ -548,14 +556,20 @@ static bool calculateConstraintSatisfaction(
548556 bool Success = calculateConstraintSatisfaction (
549557 S, FE.getNormalizedPattern (), Template, TemplateNameLoc,
550558 *SubstitutedArgs, Satisfaction, UnsignedOrNone (I));
551- if (!Success)
559+ // SFINAE errors shouldn't prevent disjunction from evaluating
560+ // FIXME: Does !Success == SFINAE errors occurred?
561+ if (!Success && Conjunction)
552562 return false ;
553563 if (!Conjunction && Satisfaction.IsSatisfied ) {
554564 Satisfaction.Details .erase (Satisfaction.Details .begin () + EffectiveDetailEndIndex,
555565 Satisfaction.Details .end ());
556566 break ;
557567 }
558568 }
569+ // Satisfaction.IsSatisfied might be overwritten.
570+ // How to handle errors here ?? Shall we substitute into the concept?
571+ if (Satisfaction.Details .size () != EffectiveDetailEndIndex)
572+ Satisfaction.IsSatisfied = false ;
559573 return true ;
560574}
561575
@@ -569,11 +583,6 @@ static bool calculateConstraintSatisfaction(
569583 S, Constraint.getConceptId ()->getNamedConcept ()->getDeclContext (),
570584 /* NewThisContext=*/ false );
571585
572- llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
573- std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
574- SubstitutionInTemplateArguments (S, Constraint, Template, MLTAL,
575- SubstitutedOuterMost);
576-
577586 Sema::InstantiatingTemplate Tpl (
578587 S, Constraint.getConceptId ()->getBeginLoc (),
579588 Sema::InstantiatingTemplate::ConstraintsCheck{},
@@ -588,6 +597,12 @@ static bool calculateConstraintSatisfaction(
588597
589598 if (Size != Satisfaction.Details .size ()) {
590599
600+ llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
601+ std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
602+ SubstitutionInTemplateArguments (S, Constraint, Template, MLTAL,
603+ SubstitutedOuterMost,
604+ PackSubstitutionIndex);
605+
591606 if (!SubstitutedArgs)
592607 return Ok;
593608
@@ -633,7 +648,7 @@ static bool calculateConstraintSatisfaction(
633648 SubstitutedConceptId.getAs <ConceptSpecializationExpr>()
634649 ->getConceptReference ()));
635650
636- Satisfaction.Details .push_back (nullptr );
651+ // Satisfaction.Details.push_back(nullptr);
637652 }
638653 return Ok;
639654}
@@ -1774,11 +1789,11 @@ NormalizedConstraint *NormalizedConstraint::fromConstraintExpr(
17741789 return nullptr ;
17751790
17761791 if (FE->isRightFold ())
1777- RHS = FoldExpandedConstraint::Create (S.getASTContext (),
1778- FE->getPattern (), Kind, RHS);
1779- else
17801792 LHS = FoldExpandedConstraint::Create (S.getASTContext (),
17811793 FE->getPattern (), Kind, LHS);
1794+ else
1795+ RHS = FoldExpandedConstraint::Create (S.getASTContext (),
1796+ FE->getPattern (), Kind, RHS);
17821797
17831798 return CompoundConstraint::Create (
17841799 S.getASTContext (), LHS,
0 commit comments