@@ -351,7 +351,11 @@ static std::optional<MultiLevelTemplateArgumentList>
351
351
SubstitutionInTemplateArguments (
352
352
Sema &S, const NormalizedConstraintWithParamMapping &Constraint,
353
353
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) {
355
359
356
360
Sema::InstantiatingTemplate Inst (
357
361
S, Constraint.getBeginLoc (),
@@ -369,7 +373,9 @@ SubstitutionInTemplateArguments(
369
373
TemplateArgumentListInfo SubstArgs;
370
374
if (Constraint.hasParameterMapping ()) {
371
375
Sema::ArgPackSubstIndexRAII SubstIndex (
372
- S, Constraint.getPackSubstitutionIndex ());
376
+ S, Constraint.getPackSubstitutionIndex ()
377
+ ? Constraint.getPackSubstitutionIndex ()
378
+ : PackSubstitutionIndex);
373
379
if (S.SubstTemplateArgumentsInParameterMapping (
374
380
Constraint.getParameterMapping (), MLTAL, SubstArgs) ||
375
381
Trap.hasErrorOccurred ())
@@ -405,11 +411,12 @@ static bool calculateConstraintSatisfaction(
405
411
llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
406
412
std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
407
413
SubstitutionInTemplateArguments (S, Constraint, Template, MLTAL,
408
- SubstitutedOuterMost);
414
+ SubstitutedOuterMost,
415
+ PackSubstitutionIndex);
409
416
if (!SubstitutedArgs)
410
417
return false ;
411
418
412
- Sema::ArgPackSubstIndexRAII (S, PackSubstitutionIndex);
419
+ Sema::ArgPackSubstIndexRAII SubstIndex (S, PackSubstitutionIndex);
413
420
ExprResult SubstitutedAtomicExpr =
414
421
EvaluateAtomicConstraint (S, Constraint.getConstraintExpr (), Template,
415
422
TemplateNameLoc, *SubstitutedArgs, Satisfaction);
@@ -526,7 +533,8 @@ static bool calculateConstraintSatisfaction(
526
533
S,
527
534
static_cast <const NormalizedConstraintWithParamMapping &>(
528
535
FE.getNormalizedPattern ()),
529
- Template, MLTAL, SubstitutedOuterMost);
536
+ // FIXME: Is PackSubstitutionIndex correct?
537
+ Template, MLTAL, SubstitutedOuterMost, S.ArgPackSubstIndex );
530
538
if (!SubstitutedArgs)
531
539
return false ;
532
540
@@ -548,14 +556,20 @@ static bool calculateConstraintSatisfaction(
548
556
bool Success = calculateConstraintSatisfaction (
549
557
S, FE.getNormalizedPattern (), Template, TemplateNameLoc,
550
558
*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)
552
562
return false ;
553
563
if (!Conjunction && Satisfaction.IsSatisfied ) {
554
564
Satisfaction.Details .erase (Satisfaction.Details .begin () + EffectiveDetailEndIndex,
555
565
Satisfaction.Details .end ());
556
566
break ;
557
567
}
558
568
}
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 ;
559
573
return true ;
560
574
}
561
575
@@ -569,11 +583,6 @@ static bool calculateConstraintSatisfaction(
569
583
S, Constraint.getConceptId ()->getNamedConcept ()->getDeclContext (),
570
584
/* NewThisContext=*/ false );
571
585
572
- llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
573
- std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
574
- SubstitutionInTemplateArguments (S, Constraint, Template, MLTAL,
575
- SubstitutedOuterMost);
576
-
577
586
Sema::InstantiatingTemplate Tpl (
578
587
S, Constraint.getConceptId ()->getBeginLoc (),
579
588
Sema::InstantiatingTemplate::ConstraintsCheck{},
@@ -588,6 +597,12 @@ static bool calculateConstraintSatisfaction(
588
597
589
598
if (Size != Satisfaction.Details .size ()) {
590
599
600
+ llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
601
+ std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
602
+ SubstitutionInTemplateArguments (S, Constraint, Template, MLTAL,
603
+ SubstitutedOuterMost,
604
+ PackSubstitutionIndex);
605
+
591
606
if (!SubstitutedArgs)
592
607
return Ok;
593
608
@@ -633,7 +648,7 @@ static bool calculateConstraintSatisfaction(
633
648
SubstitutedConceptId.getAs <ConceptSpecializationExpr>()
634
649
->getConceptReference ()));
635
650
636
- Satisfaction.Details .push_back (nullptr );
651
+ // Satisfaction.Details.push_back(nullptr);
637
652
}
638
653
return Ok;
639
654
}
@@ -1774,11 +1789,11 @@ NormalizedConstraint *NormalizedConstraint::fromConstraintExpr(
1774
1789
return nullptr ;
1775
1790
1776
1791
if (FE->isRightFold ())
1777
- RHS = FoldExpandedConstraint::Create (S.getASTContext (),
1778
- FE->getPattern (), Kind, RHS);
1779
- else
1780
1792
LHS = FoldExpandedConstraint::Create (S.getASTContext (),
1781
1793
FE->getPattern (), Kind, LHS);
1794
+ else
1795
+ RHS = FoldExpandedConstraint::Create (S.getASTContext (),
1796
+ FE->getPattern (), Kind, RHS);
1782
1797
1783
1798
return CompoundConstraint::Create (
1784
1799
S.getASTContext (), LHS,
0 commit comments