@@ -3637,6 +3637,16 @@ class Sema final {
3637
3637
bool ConsiderCudaAttrs = true,
3638
3638
bool ConsiderRequiresClauses = true);
3639
3639
3640
+ // Calculates whether the expression Constraint depends on an enclosing
3641
+ // template, for the purposes of [temp.friend] p9.
3642
+ // TemplateDepth is the 'depth' of the friend function, which is used to
3643
+ // compare whether a declaration reference is referring to a containing
3644
+ // template, or just the current friend function. A 'lower' TemplateDepth in
3645
+ // the AST refers to a 'containing' template. As the constraint is
3646
+ // uninstantiated, this is relative to the 'top' of the TU.
3647
+ bool ConstraintExpressionDependsOnEnclosingTemplate(unsigned TemplateDepth,
3648
+ const Expr *Constraint);
3649
+
3640
3650
enum class AllowedExplicit {
3641
3651
/// Allow no explicit functions to be used.
3642
3652
None,
@@ -7109,6 +7119,21 @@ class Sema final {
7109
7119
LocalInstantiationScope &Scope,
7110
7120
const MultiLevelTemplateArgumentList &TemplateArgs);
7111
7121
7122
+ /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in
7123
+ /// the case of lambdas) set up the LocalInstantiationScope of the current
7124
+ /// function.
7125
+ bool SetupConstraintScope(
7126
+ FunctionDecl *FD, llvm::Optional<ArrayRef<TemplateArgument>> TemplateArgs,
7127
+ MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope);
7128
+
7129
+ /// Used during constraint checking, sets up the constraint template arguemnt
7130
+ /// lists, and calls SetupConstraintScope to set up the
7131
+ /// LocalInstantiationScope to have the proper set of ParVarDecls configured.
7132
+ llvm::Optional<MultiLevelTemplateArgumentList>
7133
+ SetupConstraintCheckingTemplateArgumentsAndScope(
7134
+ FunctionDecl *FD, llvm::Optional<ArrayRef<TemplateArgument>> TemplateArgs,
7135
+ LocalInstantiationScope &Scope);
7136
+
7112
7137
public:
7113
7138
const NormalizedConstraint *
7114
7139
getNormalizedAssociatedConstraints(
@@ -7151,6 +7176,39 @@ class Sema final {
7151
7176
bool CheckConstraintSatisfaction(
7152
7177
const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs,
7153
7178
const MultiLevelTemplateArgumentList &TemplateArgLists,
7179
+ SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) {
7180
+ llvm::SmallVector<Expr *, 4> Converted;
7181
+ return CheckConstraintSatisfaction(Template, ConstraintExprs, Converted,
7182
+ TemplateArgLists, TemplateIDRange,
7183
+ Satisfaction);
7184
+ }
7185
+
7186
+ /// \brief Check whether the given list of constraint expressions are
7187
+ /// satisfied (as if in a 'conjunction') given template arguments.
7188
+ /// Additionally, takes an empty list of Expressions which is populated with
7189
+ /// the instantiated versions of the ConstraintExprs.
7190
+ /// \param Template the template-like entity that triggered the constraints
7191
+ /// check (either a concept or a constrained entity).
7192
+ /// \param ConstraintExprs a list of constraint expressions, treated as if
7193
+ /// they were 'AND'ed together.
7194
+ /// \param ConvertedConstraints a out parameter that will get populated with
7195
+ /// the instantiated version of the ConstraintExprs if we successfully checked
7196
+ /// satisfaction.
7197
+ /// \param TemplateArgList the multi-level list of template arguments to
7198
+ /// substitute into the constraint expression. This should be relative to the
7199
+ /// top-level (hence multi-level), since we need to instantiate fully at the
7200
+ /// time of checking.
7201
+ /// \param TemplateIDRange The source range of the template id that
7202
+ /// caused the constraints check.
7203
+ /// \param Satisfaction if true is returned, will contain details of the
7204
+ /// satisfaction, with enough information to diagnose an unsatisfied
7205
+ /// expression.
7206
+ /// \returns true if an error occurred and satisfaction could not be checked,
7207
+ /// false otherwise.
7208
+ bool CheckConstraintSatisfaction(
7209
+ const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs,
7210
+ llvm::SmallVectorImpl<Expr *> &ConvertedConstraints,
7211
+ const MultiLevelTemplateArgumentList &TemplateArgList,
7154
7212
SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction);
7155
7213
7156
7214
/// \brief Check whether the given non-dependent constraint expression is
@@ -7170,8 +7228,8 @@ class Sema final {
7170
7228
/// \returns true if an error occurred, false otherwise.
7171
7229
bool CheckFunctionConstraints(const FunctionDecl *FD,
7172
7230
ConstraintSatisfaction &Satisfaction,
7173
- SourceLocation UsageLoc = SourceLocation());
7174
-
7231
+ SourceLocation UsageLoc = SourceLocation(),
7232
+ bool ForOverloadResolution = false);
7175
7233
7176
7234
/// \brief Ensure that the given template arguments satisfy the constraints
7177
7235
/// associated with the given template, emitting a diagnostic if they do not.
@@ -8927,7 +8985,8 @@ class Sema final {
8927
8985
8928
8986
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
8929
8987
const NamedDecl *D, const TemplateArgumentList *Innermost = nullptr,
8930
- bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr);
8988
+ bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
8989
+ bool LookBeyondLambda = false, bool IncludeContainingStruct = false);
8931
8990
8932
8991
/// A context in which code is being synthesized (where a source location
8933
8992
/// alone is not sufficient to identify the context). This covers template
@@ -9635,23 +9694,21 @@ class Sema final {
9635
9694
const MultiLevelTemplateArgumentList &TemplateArgs,
9636
9695
SourceLocation Loc, DeclarationName Entity);
9637
9696
9638
- TypeSourceInfo *SubstFunctionDeclType(TypeSourceInfo *T,
9639
- const MultiLevelTemplateArgumentList &TemplateArgs,
9640
- SourceLocation Loc,
9641
- DeclarationName Entity,
9642
- CXXRecordDecl *ThisContext,
9643
- Qualifiers ThisTypeQuals);
9697
+ TypeSourceInfo *SubstFunctionDeclType(
9698
+ TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs,
9699
+ SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext,
9700
+ Qualifiers ThisTypeQuals, bool EvaluateConstraints = true);
9644
9701
void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto,
9645
9702
const MultiLevelTemplateArgumentList &Args);
9646
9703
bool SubstExceptionSpec(SourceLocation Loc,
9647
9704
FunctionProtoType::ExceptionSpecInfo &ESI,
9648
9705
SmallVectorImpl<QualType> &ExceptionStorage,
9649
9706
const MultiLevelTemplateArgumentList &Args);
9650
- ParmVarDecl *SubstParmVarDecl(ParmVarDecl *D,
9651
- const MultiLevelTemplateArgumentList &TemplateArgs ,
9652
- int indexAdjustment ,
9653
- Optional<unsigned> NumExpansions,
9654
- bool ExpectParameterPack );
9707
+ ParmVarDecl *
9708
+ SubstParmVarDecl(ParmVarDecl *D ,
9709
+ const MultiLevelTemplateArgumentList &TemplateArgs ,
9710
+ int indexAdjustment, Optional<unsigned> NumExpansions,
9711
+ bool ExpectParameterPack, bool EvaluateConstraints = true );
9655
9712
bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
9656
9713
const FunctionProtoType::ExtParameterInfo *ExtParamInfos,
9657
9714
const MultiLevelTemplateArgumentList &TemplateArgs,
@@ -9661,6 +9718,25 @@ class Sema final {
9661
9718
ExprResult SubstExpr(Expr *E,
9662
9719
const MultiLevelTemplateArgumentList &TemplateArgs);
9663
9720
9721
+ // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator
9722
+ // to disable constraint evaluation, then restore the state.
9723
+ template <typename InstTy> struct ConstraintEvalRAII {
9724
+ InstTy &TI;
9725
+ bool OldValue;
9726
+
9727
+ ConstraintEvalRAII(InstTy &TI)
9728
+ : TI(TI), OldValue(TI.getEvaluateConstraints()) {
9729
+ TI.setEvaluateConstraints(false);
9730
+ }
9731
+ ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); }
9732
+ };
9733
+
9734
+ // Unlike the above, this evaluates constraints, which should only happen at
9735
+ // 'constraint checking' time.
9736
+ ExprResult
9737
+ SubstConstraintExpr(Expr *E,
9738
+ const MultiLevelTemplateArgumentList &TemplateArgs);
9739
+
9664
9740
/// Substitute the given template arguments into a list of
9665
9741
/// expressions, expanding pack expansions if required.
9666
9742
///
@@ -9690,7 +9766,6 @@ class Sema final {
9690
9766
const MultiLevelTemplateArgumentList &TemplateArgs,
9691
9767
TemplateArgumentListInfo &Outputs);
9692
9768
9693
-
9694
9769
Decl *SubstDecl(Decl *D, DeclContext *Owner,
9695
9770
const MultiLevelTemplateArgumentList &TemplateArgs);
9696
9771
@@ -9781,7 +9856,8 @@ class Sema final {
9781
9856
const MultiLevelTemplateArgumentList &TemplateArgs);
9782
9857
9783
9858
bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC,
9784
- const MultiLevelTemplateArgumentList &TemplateArgs);
9859
+ const MultiLevelTemplateArgumentList &TemplateArgs,
9860
+ bool EvaluateConstraint);
9785
9861
9786
9862
bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
9787
9863
ParmVarDecl *Param);
0 commit comments