1414#ifndef LLVM_CLANG_SEMA_SEMA_H
1515#define LLVM_CLANG_SEMA_SEMA_H
1616
17+ #include "clang/AST/ASTConcept.h"
1718#include "clang/AST/Attr.h"
1819#include "clang/AST/Availability.h"
1920#include "clang/AST/ComparisonCategories.h"
@@ -6190,17 +6191,84 @@ class Sema {
61906191 /// A diagnostic is emitted if it is not, and false is returned.
61916192 bool CheckConstraintExpression(Expr *CE);
61926193
6193- bool CalculateConstraintSatisfaction(ConceptDecl *NamedConcept,
6194- MultiLevelTemplateArgumentList &MLTAL,
6195- Expr *ConstraintExpr,
6196- bool &IsSatisfied);
6194+ /// \brief Check whether the given list of constraint expressions are
6195+ /// satisfied (as if in a 'conjunction') given template arguments.
6196+ /// \param ConstraintExprs a list of constraint expressions, treated as if
6197+ /// they were 'AND'ed together.
6198+ /// \param TemplateArgs the list of template arguments to substitute into the
6199+ /// constraint expression.
6200+ /// \param TemplateIDRange The source range of the template id that
6201+ /// caused the constraints check.
6202+ /// \param Satisfaction if true is returned, will contain details of the
6203+ /// satisfaction, with enough information to diagnose an unsatisfied
6204+ /// expression.
6205+ /// \returns true if an error occurred and satisfaction could not be checked,
6206+ /// false otherwise.
6207+ bool CheckConstraintSatisfaction(TemplateDecl *Template,
6208+ ArrayRef<const Expr *> ConstraintExprs,
6209+ ArrayRef<TemplateArgument> TemplateArgs,
6210+ SourceRange TemplateIDRange,
6211+ ConstraintSatisfaction &Satisfaction);
6212+
6213+ bool CheckConstraintSatisfaction(ClassTemplatePartialSpecializationDecl *TD,
6214+ ArrayRef<const Expr *> ConstraintExprs,
6215+ ArrayRef<TemplateArgument> TemplateArgs,
6216+ SourceRange TemplateIDRange,
6217+ ConstraintSatisfaction &Satisfaction);
6218+
6219+ bool CheckConstraintSatisfaction(VarTemplatePartialSpecializationDecl *TD,
6220+ ArrayRef<const Expr *> ConstraintExprs,
6221+ ArrayRef<TemplateArgument> TemplateArgs,
6222+ SourceRange TemplateIDRange,
6223+ ConstraintSatisfaction &Satisfaction);
6224+
6225+ /// \brief Check whether the given non-dependent constraint expression is
6226+ /// satisfied. Returns false and updates Satisfaction with the satisfaction
6227+ /// verdict if successful, emits a diagnostic and returns true if an error
6228+ /// occured and satisfaction could not be determined.
6229+ ///
6230+ /// \returns true if an error occurred, false otherwise.
6231+ bool CheckConstraintSatisfaction(const Expr *ConstraintExpr,
6232+ ConstraintSatisfaction &Satisfaction);
61976233
61986234 /// Check that the associated constraints of a template declaration match the
61996235 /// associated constraints of an older declaration of which it is a
62006236 /// redeclaration.
62016237 bool CheckRedeclarationConstraintMatch(TemplateParameterList *Old,
62026238 TemplateParameterList *New);
62036239
6240+ /// \brief Ensure that the given template arguments satisfy the constraints
6241+ /// associated with the given template, emitting a diagnostic if they do not.
6242+ ///
6243+ /// \param Template The template to which the template arguments are being
6244+ /// provided.
6245+ ///
6246+ /// \param TemplateArgs The converted, canonicalized template arguments.
6247+ ///
6248+ /// \param TemplateIDRange The source range of the template id that
6249+ /// caused the constraints check.
6250+ ///
6251+ /// \returns true if the constrains are not satisfied or could not be checked
6252+ /// for satisfaction, false if the constraints are satisfied.
6253+ bool EnsureTemplateArgumentListConstraints(TemplateDecl *Template,
6254+ ArrayRef<TemplateArgument> TemplateArgs,
6255+ SourceRange TemplateIDRange);
6256+
6257+ /// \brief Emit diagnostics explaining why a constraint expression was deemed
6258+ /// unsatisfied.
6259+ void
6260+ DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction& Satisfaction);
6261+
6262+ /// \brief Emit diagnostics explaining why a constraint expression was deemed
6263+ /// unsatisfied.
6264+ void
6265+ DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction& Satisfaction);
6266+
6267+ /// \brief Emit diagnostics explaining why a constraint expression was deemed
6268+ /// unsatisfied because it was ill-formed.
6269+ void DiagnoseUnsatisfiedIllFormedConstraint(SourceLocation DiagnosticLocation,
6270+ StringRef Diagnostic);
6271+
62046272 // ParseObjCStringLiteral - Parse Objective-C string literals.
62056273 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
62066274 ArrayRef<Expr *> Strings);
@@ -7016,13 +7084,18 @@ class Sema {
70167084 /// contain the converted forms of the template arguments as written.
70177085 /// Otherwise, \p TemplateArgs will not be modified.
70187086 ///
7087+ /// \param ConstraintsNotSatisfied If provided, and an error occured, will
7088+ /// receive true if the cause for the error is the associated constraints of
7089+ /// the template not being satisfied by the template arguments.
7090+ ///
70197091 /// \returns true if an error occurred, false otherwise.
70207092 bool CheckTemplateArgumentList(TemplateDecl *Template,
70217093 SourceLocation TemplateLoc,
70227094 TemplateArgumentListInfo &TemplateArgs,
70237095 bool PartialTemplateArgs,
70247096 SmallVectorImpl<TemplateArgument> &Converted,
7025- bool UpdateArgsWithConversions = true);
7097+ bool UpdateArgsWithConversions = true,
7098+ bool *ConstraintsNotSatisfied = nullptr);
70267099
70277100 bool CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
70287101 TemplateArgumentLoc &Arg,
@@ -7564,6 +7637,9 @@ class Sema {
75647637 TDK_InvalidExplicitArguments,
75657638 /// Checking non-dependent argument conversions failed.
75667639 TDK_NonDependentConversionFailure,
7640+ /// The deduced arguments did not satisfy the constraints associated
7641+ /// with the template.
7642+ TDK_ConstraintsNotSatisfied,
75677643 /// Deduction failed; that's all we know.
75687644 TDK_MiscellaneousDeductionFailure,
75697645 /// CUDA Target attributes do not match.
@@ -8076,7 +8152,7 @@ class Sema {
80768152 /// constrained entity (a concept declaration or a template with associated
80778153 /// constraints).
80788154 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
8079- ConstraintsCheck, TemplateDecl *Template,
8155+ ConstraintsCheck, NamedDecl *Template,
80808156 ArrayRef<TemplateArgument> TemplateArgs,
80818157 SourceRange InstantiationRange);
80828158
@@ -8085,7 +8161,7 @@ class Sema {
80858161 /// with a template declaration or as part of the satisfaction check of a
80868162 /// concept.
80878163 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
8088- ConstraintSubstitution, TemplateDecl *Template,
8164+ ConstraintSubstitution, NamedDecl *Template,
80898165 sema::TemplateDeductionInfo &DeductionInfo,
80908166 SourceRange InstantiationRange);
80918167
0 commit comments