================
@@ -2393,9 +2413,13 @@ ExprResult
 TemplateInstantiator::TransformFunctionParmPackRefExpr(DeclRefExpr *E,
                                                        ValueDecl *PD) {
   typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
-  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found
-    = getSema().CurrentInstantiationScope->findInstantiationOf(PD);
-  assert(Found && "no instantiation for parameter pack");
+  llvm::PointerUnion<Decl *, DeclArgumentPack *> *Found =
+      getSema().CurrentInstantiationScope->getInstantiationOfIfExists(PD);
+
+  // This can happen when instantiating an expansion statement that contains
+  // a pack (e.g. `template for (auto x : {{ts...}})`).
+  if (!Found)
+    return E;
----------------
katzdm wrote:

Oh man, I spent hours debugging the assertions around this...

...I might be misremembering, but this might be to handle something like:

```cpp
template <typename... Ts>
int fn(Ts... ts) {
  template for (int i : {1, 2, 3}) {
    return (ts, ...);
  }
}
```

which, as it turns out, crashes my implementation lol. Speaking of, I have a 
_great_ suggestion for a test case! 😄 

But the interesting thing about the above is that the expansion statement can 
be instantiated even while the function is dependent - my approach was to 
instantiate expansion statements as eagerly as possible to facilitate early 
diagnosis.

https://github.com/llvm/llvm-project/pull/165195
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to