[clang] [clang][Sema] Ignore the parentheses in the guard of DiagnoseUnexpandedParameterPack (PR #86401)

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 27 16:31:20 PDT 2024


dwblaikie wrote:

> @dwblaikie Feel free to checkout this patch locally and see if it resolves the original issue  - I won't merge it until you confirm it works or discover another issue that goes beyond the scope of this patch. (e.g. another aforementioned issue)

First glance it seems it does not resolve the original issue (still seeing a crash, with this patch applied, on the original source). I'll try to reduce another test case.


> > Hmm, actually - does this fix address /other/ ways a pack could appear, like this? https://godbolt.org/z/oez8TbGqM
> > Presumably a pack could appear in a variety of expressions, not just wrapped in parens - could be in a function call (as in the above example), or nested arbitrarily more deeply in the expression in any number of other expressions?
> 
> It fixes it as well, although with an unused-expression warning.

Oh, that surprises me - not sure how ignoring parens could help the case where it's a function call... 

Oh, I was looking at the wrong parens, it's the line 9 `(ts)` parens. OK, change /that/ into a function call (and this time I've actually applied this patch locally and tested this, and it does seem to still crash, even with this patch applied):

```
template<typename... Ts>
void f1(Ts... ts);
template <typename... Ts>
void f1(Ts... ts) {
  [&](auto... indexes) {
    ([&] {
        f1(ts);
        indexes;
      }, ...);
  };
}
void f2() { f1(); }
```

But perhaps this ^ is what you're referring to \/ when you mention "if you turn the capture of the inner lambda to a pack, e.g. `ts`"

> Aside: it crashes again if you turn the capture of the inner lambda to a pack, e.g. `ts` - that is a different story and is being tracked in #18873, which indicates that the capture of packs is still broken as of now.

But is it a different story? Whet I run the above example, with this patch applied, I get an identical stack trace:

```
...
#12 0x00005637d1f3b0f1 clang::Sema::DiagnoseUnexpandedParameterPack(clang::Expr*, clang::Sema::UnexpandedParameterPackContext) 
#13 0x00005637d155c166 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) 
#14 0x00005637d19cf202 clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) 
#15 0x00005637d1e352f8 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateIn
stantiator>::StmtDiscardKind)
...
```





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


More information about the cfe-commits mailing list