[libcxx-commits] [clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

Matheus Izvekov via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 29 11:41:07 PDT 2024


================
@@ -1144,6 +1164,46 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
                                      PointOfInstantiation, Satisfaction);
 }
 
+bool Sema::CheckFunctionConstraintsWithoutInstantiation(
+    SourceLocation PointOfInstantiation, FunctionTemplateDecl *Template,
+    ArrayRef<TemplateArgument> TemplateArgs,
+    ConstraintSatisfaction &Satisfaction) {
+  FunctionDecl *FD = Template->getTemplatedDecl();
+  SmallVector<const Expr *, 3> TemplateAC;
+  Template->getAssociatedConstraints(TemplateAC);
+  if (TemplateAC.empty()) {
+    Satisfaction.IsSatisfied = true;
+    return false;
+  }
+
+  // Enter the scope of this instantiation. We don't use
+  // PushDeclContext because we don't have a scope.
+  LocalInstantiationScope Scope(*this);
+
+  // Collect the list of template arguments relative to the 'primary'
+  // template. We need the entire list, since the constraint is completely
+  // uninstantiated at this point.
+  DeclContext *NextDC = FD->getFriendObjectKind() ? FD->getLexicalDeclContext()
+                                                  : FD->getDeclContext();
+  MultiLevelTemplateArgumentList MLTAL =
+      getTemplateInstantiationArgs(FD, NextDC,
+                                   /*Final=*/false,
+                                   /*Innermost=*/TemplateArgs,
+                                   /*RelativeToPrimary=*/true,
+                                   /*Pattern=*/nullptr,
+                                   /*ForConstraintInstantiation=*/true);
+
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
+    ThisQuals = Method->getMethodQualifiers();
+    Record = Method->getParent();
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
----------------
mizvekov wrote:

```suggestion
  std::optional<CXXThisScopeRAII> ThisScope;
  if (auto *Method = dyn_cast<CXXMethodDecl>(FD))
    ThisSope.emplace(*this,  Method->getParent(), Method->getMethodQualifiers());
```

https://github.com/llvm/llvm-project/pull/102857


More information about the libcxx-commits mailing list