@@ -3673,6 +3673,31 @@ class Sema final {
3673
3673
bool ConsiderCudaAttrs = true,
3674
3674
bool ConsiderRequiresClauses = true);
3675
3675
3676
+ // Calculates whether the expression Constraint depends on an enclosing
3677
+ // template, for the purposes of [temp.friend] p9.
3678
+ // TemplateDepth is the 'depth' of the friend function, which is used to
3679
+ // compare whether a declaration reference is referring to a containing
3680
+ // template, or just the current friend function. A 'lower' TemplateDepth in
3681
+ // the AST refers to a 'containing' template. As the constraint is
3682
+ // uninstantiated, this is relative to the 'top' of the TU.
3683
+ bool ConstraintExpressionDependsOnEnclosingTemplate(unsigned TemplateDepth,
3684
+ const Expr *Constraint);
3685
+
3686
+ // Calculates whether the friend function depends on an enclosing template for
3687
+ // the purposes of [temp.friend] p9.
3688
+ bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD);
3689
+
3690
+ // Calculates whether two constraint expressions are equal irrespective of a
3691
+ // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and
3692
+ // 'New', which are the "source" of the constraint, since this is necessary
3693
+ // for figuring out the relative 'depth' of the constraint. The depth of the
3694
+ // 'primary template' and the 'instantiated from' templates aren't necessarily
3695
+ // the same, such as a case when one is a 'friend' defined in a class.
3696
+ bool AreConstraintExpressionsEqual(const NamedDecl *Old,
3697
+ const Expr *OldConstr,
3698
+ const NamedDecl *New,
3699
+ const Expr *NewConstr);
3700
+
3676
3701
enum class AllowedExplicit {
3677
3702
/// Allow no explicit functions to be used.
3678
3703
None,
@@ -7152,6 +7177,21 @@ class Sema final {
7152
7177
LocalInstantiationScope &Scope,
7153
7178
const MultiLevelTemplateArgumentList &TemplateArgs);
7154
7179
7180
+ /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in
7181
+ /// the case of lambdas) set up the LocalInstantiationScope of the current
7182
+ /// function.
7183
+ bool SetupConstraintScope(
7184
+ FunctionDecl *FD, llvm::Optional<ArrayRef<TemplateArgument>> TemplateArgs,
7185
+ MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope);
7186
+
7187
+ /// Used during constraint checking, sets up the constraint template arguemnt
7188
+ /// lists, and calls SetupConstraintScope to set up the
7189
+ /// LocalInstantiationScope to have the proper set of ParVarDecls configured.
7190
+ llvm::Optional<MultiLevelTemplateArgumentList>
7191
+ SetupConstraintCheckingTemplateArgumentsAndScope(
7192
+ FunctionDecl *FD, llvm::Optional<ArrayRef<TemplateArgument>> TemplateArgs,
7193
+ LocalInstantiationScope &Scope);
7194
+
7155
7195
public:
7156
7196
const NormalizedConstraint *
7157
7197
getNormalizedAssociatedConstraints(
@@ -7194,6 +7234,39 @@ class Sema final {
7194
7234
bool CheckConstraintSatisfaction(
7195
7235
const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs,
7196
7236
const MultiLevelTemplateArgumentList &TemplateArgLists,
7237
+ SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) {
7238
+ llvm::SmallVector<Expr *, 4> Converted;
7239
+ return CheckConstraintSatisfaction(Template, ConstraintExprs, Converted,
7240
+ TemplateArgLists, TemplateIDRange,
7241
+ Satisfaction);
7242
+ }
7243
+
7244
+ /// \brief Check whether the given list of constraint expressions are
7245
+ /// satisfied (as if in a 'conjunction') given template arguments.
7246
+ /// Additionally, takes an empty list of Expressions which is populated with
7247
+ /// the instantiated versions of the ConstraintExprs.
7248
+ /// \param Template the template-like entity that triggered the constraints
7249
+ /// check (either a concept or a constrained entity).
7250
+ /// \param ConstraintExprs a list of constraint expressions, treated as if
7251
+ /// they were 'AND'ed together.
7252
+ /// \param ConvertedConstraints a out parameter that will get populated with
7253
+ /// the instantiated version of the ConstraintExprs if we successfully checked
7254
+ /// satisfaction.
7255
+ /// \param TemplateArgList the multi-level list of template arguments to
7256
+ /// substitute into the constraint expression. This should be relative to the
7257
+ /// top-level (hence multi-level), since we need to instantiate fully at the
7258
+ /// time of checking.
7259
+ /// \param TemplateIDRange The source range of the template id that
7260
+ /// caused the constraints check.
7261
+ /// \param Satisfaction if true is returned, will contain details of the
7262
+ /// satisfaction, with enough information to diagnose an unsatisfied
7263
+ /// expression.
7264
+ /// \returns true if an error occurred and satisfaction could not be checked,
7265
+ /// false otherwise.
7266
+ bool CheckConstraintSatisfaction(
7267
+ const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs,
7268
+ llvm::SmallVectorImpl<Expr *> &ConvertedConstraints,
7269
+ const MultiLevelTemplateArgumentList &TemplateArgList,
7197
7270
SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction);
7198
7271
7199
7272
/// \brief Check whether the given non-dependent constraint expression is
@@ -7213,8 +7286,8 @@ class Sema final {
7213
7286
/// \returns true if an error occurred, false otherwise.
7214
7287
bool CheckFunctionConstraints(const FunctionDecl *FD,
7215
7288
ConstraintSatisfaction &Satisfaction,
7216
- SourceLocation UsageLoc = SourceLocation());
7217
-
7289
+ SourceLocation UsageLoc = SourceLocation(),
7290
+ bool ForOverloadResolution = false);
7218
7291
7219
7292
/// \brief Ensure that the given template arguments satisfy the constraints
7220
7293
/// associated with the given template, emitting a diagnostic if they do not.
@@ -8222,12 +8295,19 @@ class Sema final {
8222
8295
TPL_TemplateTemplateArgumentMatch
8223
8296
};
8224
8297
8225
- bool TemplateParameterListsAreEqual(TemplateParameterList *New,
8226
- TemplateParameterList *Old,
8227
- bool Complain,
8228
- TemplateParameterListEqualKind Kind,
8229
- SourceLocation TemplateArgLoc
8230
- = SourceLocation());
8298
+ bool TemplateParameterListsAreEqual(
8299
+ const NamedDecl *NewInstFrom, TemplateParameterList *New,
8300
+ const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain,
8301
+ TemplateParameterListEqualKind Kind,
8302
+ SourceLocation TemplateArgLoc = SourceLocation());
8303
+
8304
+ bool TemplateParameterListsAreEqual(
8305
+ TemplateParameterList *New, TemplateParameterList *Old, bool Complain,
8306
+ TemplateParameterListEqualKind Kind,
8307
+ SourceLocation TemplateArgLoc = SourceLocation()) {
8308
+ return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain,
8309
+ Kind, TemplateArgLoc);
8310
+ }
8231
8311
8232
8312
bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams);
8233
8313
@@ -8962,7 +9042,8 @@ class Sema final {
8962
9042
8963
9043
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
8964
9044
const NamedDecl *D, const TemplateArgumentList *Innermost = nullptr,
8965
- bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr);
9045
+ bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
9046
+ bool LookBeyondLambda = false, bool IncludeContainingStruct = false);
8966
9047
8967
9048
/// A context in which code is being synthesized (where a source location
8968
9049
/// alone is not sufficient to identify the context). This covers template
@@ -9670,23 +9751,21 @@ class Sema final {
9670
9751
const MultiLevelTemplateArgumentList &TemplateArgs,
9671
9752
SourceLocation Loc, DeclarationName Entity);
9672
9753
9673
- TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
9674
- const MultiLevelTemplateArgumentList &TemplateArgs,
9675
- SourceLocation Loc,
9676
- DeclarationName Entity,
9677
- CXXRecordDecl *ThisContext,
9678
- Qualifiers ThisTypeQuals);
9754
+ TypeSourceInfo *SubstFunctionDeclType(
9755
+ TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs,
9756
+ SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext,
9757
+ Qualifiers ThisTypeQuals, bool EvaluateConstraints = true);
9679
9758
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
9680
9759
const MultiLevelTemplateArgumentList &Args);
9681
9760
bool SubstExceptionSpec(SourceLocation Loc,
9682
9761
FunctionProtoType::ExceptionSpecInfo &ESI,
9683
9762
SmallVectorImpl<QualType> &ExceptionStorage,
9684
9763
const MultiLevelTemplateArgumentList &Args);
9685
- ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
9686
- const MultiLevelTemplateArgumentList &TemplateArgs ,
9687
- int indexAdjustment ,
9688
- Optional<unsigned> NumExpansions,
9689
- bool ExpectParameterPack );
9764
+ ParmVarDecl *
9765
+ SubstParmVarDecl(ParmVarDecl *D ,
9766
+ const MultiLevelTemplateArgumentList &TemplateArgs ,
9767
+ int indexAdjustment, Optional<unsigned> NumExpansions,
9768
+ bool ExpectParameterPack, bool EvaluateConstraints = true );
9690
9769
bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
9691
9770
const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
9692
9771
const MultiLevelTemplateArgumentList &TemplateArgs,
@@ -9696,6 +9775,25 @@ class Sema final {
9696
9775
ExprResult SubstExpr(Expr *E,
9697
9776
const MultiLevelTemplateArgumentList &TemplateArgs);
9698
9777
9778
+ // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator
9779
+ // to disable constraint evaluation, then restore the state.
9780
+ template <typename InstTy> struct ConstraintEvalRAII {
9781
+ InstTy &TI;
9782
+ bool OldValue;
9783
+
9784
+ ConstraintEvalRAII(InstTy &TI)
9785
+ : TI(TI), OldValue(TI.getEvaluateConstraints()) {
9786
+ TI.setEvaluateConstraints(false);
9787
+ }
9788
+ ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); }
9789
+ };
9790
+
9791
+ // Unlike the above, this evaluates constraints, which should only happen at
9792
+ // 'constraint checking' time.
9793
+ ExprResult
9794
+ SubstConstraintExpr(Expr *E,
9795
+ const MultiLevelTemplateArgumentList &TemplateArgs);
9796
+
9699
9797
/// Substitute the given template arguments into a list of
9700
9798
/// expressions, expanding pack expansions if required.
9701
9799
///
@@ -9725,7 +9823,6 @@ class Sema final {
9725
9823
const MultiLevelTemplateArgumentList &TemplateArgs,
9726
9824
TemplateArgumentListInfo &Outputs);
9727
9825
9728
-
9729
9826
Decl *SubstDecl(Decl *D, DeclContext *Owner,
9730
9827
const MultiLevelTemplateArgumentList &TemplateArgs);
9731
9828
@@ -9816,7 +9913,8 @@ class Sema final {
9816
9913
const MultiLevelTemplateArgumentList &TemplateArgs);
9817
9914
9818
9915
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC,
9819
- const MultiLevelTemplateArgumentList &TemplateArgs);
9916
+ const MultiLevelTemplateArgumentList &TemplateArgs,
9917
+ bool EvaluateConstraint);
9820
9918
9821
9919
bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
9822
9920
ParmVarDecl *Param);
0 commit comments