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

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 9 00:34:11 PDT 2024


================
@@ -1916,9 +1935,33 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
     // template parameter.
   }
 
+  if (SemaRef.CurrentInstantiationScope) {
+    if (isSubstitutingConstraints() && isa<ParmVarDecl>(D) &&
+        maybeInstantiateFunctionParameterToScope(cast<ParmVarDecl>(D)))
+      return nullptr;
+  }
+
   return SemaRef.FindInstantiatedDecl(Loc, cast<NamedDecl>(D), TemplateArgs);
 }
 
+bool TemplateInstantiator::maybeInstantiateFunctionParameterToScope(
+    ParmVarDecl *OldParm) {
+  if (SemaRef.CurrentInstantiationScope->findInstantiationUnsafe(OldParm))
+    return false;
+  // The current context might have been changed in the process of transforming
+  // lambda expression. So resume it before we substitute into the parameter.
----------------
cor3ntin wrote:

```suggestion
  // lambda expression. So restore it before we substitute into the parameter.
```

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


More information about the cfe-commits mailing list