65
65
#include "clang/Sema/Redeclaration.h"
66
66
#include "clang/Sema/Scope.h"
67
67
#include "clang/Sema/SemaBase.h"
68
+ #include "clang/Sema/SemaConcept.h"
68
69
#include "clang/Sema/TypoCorrection.h"
69
70
#include "clang/Sema/Weak.h"
70
71
#include "llvm/ADT/APInt.h"
@@ -11688,8 +11689,9 @@ class Sema final : public SemaBase {
11688
11689
ExprResult
11689
11690
CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
11690
11691
const DeclarationNameInfo &ConceptNameInfo,
11691
- NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
11692
- const TemplateArgumentListInfo *TemplateArgs);
11692
+ NamedDecl *FoundDecl, TemplateDecl *NamedConcept,
11693
+ const TemplateArgumentListInfo *TemplateArgs,
11694
+ bool DoCheckConstraintSatisfaction = true);
11693
11695
11694
11696
void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc);
11695
11697
void diagnoseMissingTemplateArguments(const CXXScopeSpec &SS,
@@ -12002,6 +12004,13 @@ class Sema final : public SemaBase {
12002
12004
bool UpdateArgsWithConversions = true,
12003
12005
bool *ConstraintsNotSatisfied = nullptr);
12004
12006
12007
+ bool CheckTemplateArgumentList(
12008
+ TemplateDecl *Template, TemplateParameterList *Params,
12009
+ SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs,
12010
+ const DefaultArguments &DefaultArgs, bool PartialTemplateArgs,
12011
+ CheckTemplateArgumentInfo &CTAI, bool UpdateArgsWithConversions = true,
12012
+ bool *ConstraintsNotSatisfied = nullptr);
12013
+
12005
12014
bool CheckTemplateTypeArgument(
12006
12015
TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
12007
12016
SmallVectorImpl<TemplateArgument> &SugaredConverted,
@@ -12776,6 +12785,9 @@ class Sema final : public SemaBase {
12776
12785
void MarkUsedTemplateParameters(ArrayRef<TemplateArgument> TemplateArgs,
12777
12786
unsigned Depth, llvm::SmallBitVector &Used);
12778
12787
12788
+ void MarkUsedTemplateParameters(ArrayRef<TemplateArgumentLoc> TemplateArgs,
12789
+ unsigned Depth, llvm::SmallBitVector &Used);
12790
+
12779
12791
void
12780
12792
MarkDeducedTemplateParameters(const FunctionTemplateDecl *FunctionTemplate,
12781
12793
llvm::SmallBitVector &Deduced) {
@@ -13073,6 +13085,8 @@ class Sema final : public SemaBase {
13073
13085
/// Whether we're substituting into constraints.
13074
13086
bool InConstraintSubstitution;
13075
13087
13088
+ bool InParameterMappingSubstitution;
13089
+
13076
13090
/// The point of instantiation or synthesis within the source code.
13077
13091
SourceLocation PointOfInstantiation;
13078
13092
@@ -13338,6 +13352,11 @@ class Sema final : public SemaBase {
13338
13352
const MultiLevelTemplateArgumentList &TemplateArgs,
13339
13353
TemplateArgumentListInfo &Outputs);
13340
13354
13355
+ bool SubstTemplateArgumentsInParameterMapping(
13356
+ ArrayRef<TemplateArgumentLoc> Args, SourceLocation BaseLoc,
13357
+ const MultiLevelTemplateArgumentList &TemplateArgs,
13358
+ TemplateArgumentListInfo &Out, bool BuildPackExpansionTypes);
13359
+
13341
13360
/// Retrieve the template argument list(s) that should be used to
13342
13361
/// instantiate the definition of the given declaration.
13343
13362
///
@@ -13799,6 +13818,12 @@ class Sema final : public SemaBase {
13799
13818
CodeSynthesisContexts.back().InConstraintSubstitution;
13800
13819
}
13801
13820
13821
+ bool inParameterMappingSubstitution() const {
13822
+ return !CodeSynthesisContexts.empty() &&
13823
+ CodeSynthesisContexts.back().InParameterMappingSubstitution &&
13824
+ !inConstraintSubstitution();
13825
+ }
13826
+
13802
13827
using EntityPrinter = llvm::function_ref<void(llvm::raw_ostream &)>;
13803
13828
13804
13829
/// \brief create a Requirement::SubstitutionDiagnostic with only a
@@ -14683,6 +14708,10 @@ class Sema final : public SemaBase {
14683
14708
SatisfactionStack.swap(NewSS);
14684
14709
}
14685
14710
14711
+ using ConstrainedDeclOrNestedRequirement =
14712
+ llvm::PointerUnion<const NamedDecl *,
14713
+ const concepts::NestedRequirement *>;
14714
+
14686
14715
/// Check whether the given expression is a valid constraint expression.
14687
14716
/// A diagnostic is emitted if it is not, false is returned, and
14688
14717
/// PossibleNonPrimary will be set to true if the failure might be due to a
@@ -14707,44 +14736,12 @@ class Sema final : public SemaBase {
14707
14736
/// \returns true if an error occurred and satisfaction could not be checked,
14708
14737
/// false otherwise.
14709
14738
bool CheckConstraintSatisfaction(
14710
- const NamedDecl *Template ,
14739
+ ConstrainedDeclOrNestedRequirement Entity ,
14711
14740
ArrayRef<AssociatedConstraint> AssociatedConstraints,
14712
14741
const MultiLevelTemplateArgumentList &TemplateArgLists,
14713
- SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) {
14714
- llvm::SmallVector<Expr *, 4> Converted;
14715
- return CheckConstraintSatisfaction(Template, AssociatedConstraints,
14716
- Converted, TemplateArgLists,
14717
- TemplateIDRange, Satisfaction);
14718
- }
14719
-
14720
- /// \brief Check whether the given list of constraint expressions are
14721
- /// satisfied (as if in a 'conjunction') given template arguments.
14722
- /// Additionally, takes an empty list of Expressions which is populated with
14723
- /// the instantiated versions of the ConstraintExprs.
14724
- /// \param Template the template-like entity that triggered the constraints
14725
- /// check (either a concept or a constrained entity).
14726
- /// \param ConstraintExprs a list of constraint expressions, treated as if
14727
- /// they were 'AND'ed together.
14728
- /// \param ConvertedConstraints a out parameter that will get populated with
14729
- /// the instantiated version of the ConstraintExprs if we successfully checked
14730
- /// satisfaction.
14731
- /// \param TemplateArgList the multi-level list of template arguments to
14732
- /// substitute into the constraint expression. This should be relative to the
14733
- /// top-level (hence multi-level), since we need to instantiate fully at the
14734
- /// time of checking.
14735
- /// \param TemplateIDRange The source range of the template id that
14736
- /// caused the constraints check.
14737
- /// \param Satisfaction if true is returned, will contain details of the
14738
- /// satisfaction, with enough information to diagnose an unsatisfied
14739
- /// expression.
14740
- /// \returns true if an error occurred and satisfaction could not be checked,
14741
- /// false otherwise.
14742
- bool CheckConstraintSatisfaction(
14743
- const NamedDecl *Template,
14744
- ArrayRef<AssociatedConstraint> AssociatedConstraints,
14745
- llvm::SmallVectorImpl<Expr *> &ConvertedConstraints,
14746
- const MultiLevelTemplateArgumentList &TemplateArgList,
14747
- SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction);
14742
+ SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction,
14743
+ const ConceptReference *TopLevelConceptId = nullptr,
14744
+ Expr **ConvertedExpr = nullptr);
14748
14745
14749
14746
/// \brief Check whether the given non-dependent constraint expression is
14750
14747
/// satisfied. Returns false and updates Satisfaction with the satisfaction
@@ -14810,16 +14807,17 @@ class Sema final : public SemaBase {
14810
14807
/// \param First whether this is the first time an unsatisfied constraint is
14811
14808
/// diagnosed for this error.
14812
14809
void DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction,
14810
+ SourceLocation Loc = {},
14813
14811
bool First = true);
14814
14812
14815
14813
/// \brief Emit diagnostics explaining why a constraint expression was deemed
14816
14814
/// unsatisfied.
14817
14815
void
14818
- DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction ,
14816
+ DiagnoseUnsatisfiedConstraint(const ConceptSpecializationExpr *ConstraintExpr ,
14819
14817
bool First = true);
14820
14818
14821
14819
const NormalizedConstraint *getNormalizedAssociatedConstraints(
14822
- const NamedDecl *ConstrainedDecl ,
14820
+ ConstrainedDeclOrNestedRequirement Entity ,
14823
14821
ArrayRef<AssociatedConstraint> AssociatedConstraints);
14824
14822
14825
14823
/// \brief Check whether the given declaration's associated constraints are
@@ -14844,6 +14842,9 @@ class Sema final : public SemaBase {
14844
14842
const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
14845
14843
const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
14846
14844
14845
+ llvm::DenseMap<llvm::FoldingSetNodeID, CachedConceptIdConstraint>
14846
+ ConceptIdSatisfactionCache;
14847
+
14847
14848
private:
14848
14849
/// Caches pairs of template-like decls whose associated constraints were
14849
14850
/// checked for subsumption and whether or not the first's constraints did in
@@ -14854,7 +14855,8 @@ class Sema final : public SemaBase {
14854
14855
/// constrained declarations). If an error occurred while normalizing the
14855
14856
/// associated constraints of the template or concept, nullptr will be cached
14856
14857
/// here.
14857
- llvm::DenseMap<const NamedDecl *, NormalizedConstraint *> NormalizationCache;
14858
+ llvm::DenseMap<ConstrainedDeclOrNestedRequirement, NormalizedConstraint *>
14859
+ NormalizationCache;
14858
14860
14859
14861
llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &>
14860
14862
SatisfactionCache;
0 commit comments