[libcxx-commits] [clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)
Younan Zhang via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Nov 3 06:51:01 PST 2024
================
@@ -1109,12 +1109,50 @@ bool Sema::EnsureTemplateArgumentListConstraints(
return false;
}
-bool Sema::CheckInstantiatedFunctionTemplateConstraints(
+static bool CheckFunctionConstraintsWithoutInstantiation(
+ Sema &SemaRef, SourceLocation PointOfInstantiation,
+ FunctionTemplateDecl *Template, ArrayRef<TemplateArgument> TemplateArgs,
+ ConstraintSatisfaction &Satisfaction) {
+ SmallVector<const Expr *, 3> TemplateAC;
+ Template->getAssociatedConstraints(TemplateAC);
+ if (TemplateAC.empty()) {
+ Satisfaction.IsSatisfied = true;
+ return false;
+ }
+
+ LocalInstantiationScope Scope(SemaRef);
+
+ FunctionDecl *FD = Template->getTemplatedDecl();
+ // 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.
+ MultiLevelTemplateArgumentList MLTAL =
+ SemaRef.getTemplateInstantiationArgs(FD, /*DC=*/nullptr,
+ /*Final=*/false,
+ /*Innermost=*/TemplateArgs,
+ /*RelativeToPrimary=*/true,
+ /*ForConstraintInstantiation=*/true);
+
+ std::optional<Sema::CXXThisScopeRAII> ThisScope;
+ if (auto *Method = dyn_cast<CXXMethodDecl>(FD))
+ ThisScope.emplace(SemaRef, /*Record=*/Method->getParent(),
+ /*ThisQuals=*/Method->getMethodQualifiers());
----------------
zyn0217 wrote:
I tried to contrive a case like
```cpp
template <class T>
struct S {
void foo() requires(__is_same_as(S&, decltype(*this))) {}
};
void g() {
S<int>().foo();
}
```
But there would still be no difference if we did the `CXXThisScopeRAII` things away. (It always compiles.)
Maybe I'm running out of ideas right now, so let's just preserve these "strange but plausible" things?
https://github.com/llvm/llvm-project/pull/102857
More information about the libcxx-commits
mailing list